Created
March 16, 2025 22:29
-
-
Save tildejustin/5a70caf2857fceb1683789ea259c2267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import requests | |
def get_runs_until(game: str, until: datetime.date) -> list[str]: | |
runs = [] | |
next_uri = f"https://www.speedrun.com/api/v1/runs?game={game}&orderby=submitted&direction=desc&=&max=200" | |
while next_uri != None: | |
res = requests.get(next_uri).json() | |
if not res.get("data"): | |
break | |
for run in res["data"]: | |
date_t = datetime.datetime.fromisoformat(run["submitted"]).astimezone(datetime.timezone(datetime.timedelta(hours=13))) | |
# assuming filtered data, which src isn't known to do perfectly | |
if date_t.date() < until: | |
return runs | |
runs.append(run) | |
next_block = res["pagination"]["links"] | |
next_uri = None | |
for block in next_block: | |
if block["rel"] == "next": | |
next_uri = block["uri"] | |
until = datetime.date(2025, 2, 24) | |
one_day = datetime.timedelta(days=1) | |
runs = [] | |
# mc: j1npme6p, mcce: nd2e9erd | |
runs.extend(get_runs_until("j1npme6p", until)) | |
runs.extend(get_runs_until("nd2e9erd", until)) | |
runs.sort(key = lambda run: datetime.datetime.fromisoformat(run["submitted"])) | |
by_date = { until-one_day:0 } | |
for run in runs: | |
run_date = datetime.datetime.fromisoformat(run["submitted"]).astimezone(datetime.timezone(datetime.timedelta(hours=13))).date() | |
# assuming that keys()[-1] has correct ordering which there is no promise for but it worked :shrug: | |
if list(by_date.keys())[-1] != run_date: | |
by_date[run_date] = by_date[run_date-one_day] | |
by_date[run_date] += 1 | |
for k, v in by_date.items(): | |
print(f"{k}: {v}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment