-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenera-llista.py
28 lines (23 loc) · 1021 Bytes
/
genera-llista.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
import json
URL_PROGRAMA = "https://api.ccma.cat/videos?version=2.0&_format=json&items_pagina=1500&tipus_contingut=PPD&ordre=-data_emissio&produccio=1001217"
def main():
contes = {}
response = requests.get(URL_PROGRAMA, allow_redirects=True)
data = response.json()
for item in data["resposta"]["items"]["item"]:
try:
if item["idiomes"][0]["id"] == "PU_CATALA":
titol = item["titol"]
id = item["id"]
if titol and id:
item_url = f"https://dinamics.ccma.cat/pvideo/media.jsp?media=video&idint={id}"
item_response = requests.get(item_url, allow_redirects=True)
item_data = item_response.json()
contes[titol] = item_data["media"]["url"][0]["file"]
except Exception:
pass
with open("contes.json", "w") as file:
json.dump(contes, file, ensure_ascii=False, indent=4)
if __name__ == "__main__":
main()