import subprocess import json with open("./results.json", "r") as f: sports = json.load(f) ret = {} for sport in sports: ret[sport] = {} for event in sports[sport]: ret[sport][event] = {} ret[sport][event]["type"] = "team" if sports[sport][event][0]["participant"]["__typename"] == "GameTeam" else "single" ret[sport][event]["participants"] = [] print(f"{sport} >> {event} ".ljust(50), end="") for i in range(len(sports[sport][event])): ret[sport][event]["participants"].append({}) try: ret[sport][event]["participants"][i]["country"] = sports[sport][event][i]["noc"]["name"] except: try: ret[sport][event]["participants"][i]["country"] = sports[sport][event][i]["participant"]["countryObject"]["name"] except: ret[sport][event]["participants"][i]["country"] = "None" if ret[sport][event]["type"] == "single": ret[sport][event]["participants"][i]["athlete"] = {} ret[sport][event]["participants"][i]["athlete"]["meta_url"] = sports[sport][event][i]["participant"]["meta"]["url"] ret[sport][event]["participants"][i]["athlete"]["name"] = f'{sports[sport][event][i]["participant"]["name"]} {sports[sport][event][i]["participant"]["surname"]}' try: template = sports[sport][event][i]["participant"]["thumbnail"]["urlTemplate"] img = f'https://img.olympics.com/images/image/private/t_1-1_300/f_auto{template[template.index("}")+1:]}' except: img = f'https://gstatic.olympics.com/s1/f_auto/static/light/flag/paris-2024/olympic/3x2/{sports[sport][event][i]["participant"]["countryObject"]["triLetterCode"]}.png' ret[sport][event]["participants"][i]["athlete"]["image"] = img else: try: ret[sport][event]["participants"][i]["img"] = f'https://gstatic.olympics.com/s1/f_auto/static/light/flag/paris-2024/olympic/3x2/{sports[sport][event][i]["noc"]["code"]}.png' except: ret[sport][event]["participants"][i]["img"] = None print("o", end="") print() with open("./data.json", "w") as f: json.dump(ret, f, ensure_ascii=False, indent=4, sort_keys=True)