This commit is contained in:
Lennart J. Kurzweg (Nx2)
2024-08-16 19:28:51 +02:00
commit 9d75757fec
20 changed files with 287594 additions and 0 deletions

44
get_data/clean-results.py Normal file
View File

@@ -0,0 +1,44 @@
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)

15
get_data/get-events.py Normal file
View File

@@ -0,0 +1,15 @@
import subprocess
import json
with open("./sports.json", "r") as f:
sports = json.load(f)
ret = {}
for sport in sports:
stdout = subprocess.check_output(f'./get-events.sh {sport}', shell=True)
events = json.loads(stdout)
ret[sport] = events
with open("./events.json", "w") as f:
json.dump(ret, f, indent=4, ensure_ascii=False, sort_keys=True)

12
get_data/get-events.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
args=("$@")
curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" https://olympics.com/en/olympic-games/tokyo-2020/results/${args[0]} |\
sed -E 's->->\n-g' |\
rg -A 9999999999999999 '<script id="__NEXT_DATA__" type="application/json">' |\
sed -n 2p |\
rev |\
cut -c10- |\
rev |\
jq '[.["props"]["pageProps"]["allEvents"][]["slug"]]'

18
get_data/get-results.py Normal file
View File

@@ -0,0 +1,18 @@
import subprocess
import json
with open("./events.json", "r") as f:
sports = json.load(f)
ret = {}
for sport in sports:
ret[sport] = {}
for event in sports[sport]:
stdout = subprocess.check_output(f'./get-results.sh {sport} {event}', shell=True)
result = json.loads(stdout)
ret[sport][event] = result
print(f"Done with {sport} >> {event}")
with open("./results.json", "w") as f:
json.dump(ret, f, indent=4, ensure_ascii=False, sort_keys=True)

12
get_data/get-results.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
args=("$@")
curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" https://olympics.com/en/olympic-games/tokyo-2020/results/${args[0]}/${args[1]} |\
sed -E 's->->\n-g' |\
rg -A 9999999999999999 '<script id="__NEXT_DATA__" type="application/json">' |\
sed -n 2p |\
rev |\
cut -c10- |\
rev |\
jq '.["props"]["pageProps"]["gameEvent"]["results"]["standing"][0:9]'

12
get_data/get.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
args=("$@")
curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" https://olympics.com/en/olympic-games/tokyo-2020/results/${args[0]} |\
sed -E 's->->\n-g' |\
rg -A 9999999999999999 '<script id="__NEXT_DATA__" type="application/json">' |\
sed -n 2p |\
rev |\
cut -c10- |\
rev |\
jq '[.["props"]["pageProps"]["allEvents"][]["slug"]]'