Skip to content

Instantly share code, notes, and snippets.

@ManicJamie
Created August 26, 2023 00:51
Show Gist options
  • Save ManicJamie/6fe281e04346c5b9d3bfa731f62aed28 to your computer and use it in GitHub Desktop.
Save ManicJamie/6fe281e04346c5b9d3bfa731f62aed28 to your computer and use it in GitHub Desktop.
SRC getTimes
import srcomapi
from srcomapi.datatypes import *
import csv
api = srcomapi.SpeedrunCom()
game_id = "76rqmld8"
game : Game = api.get_game(game_id)
"""
# Uncomment this area to get game by name
game_name = input("Enter game name:")
game = api.search(Game, {"name": game_name})[0]
game_id = game.data["id"]
"""
print(game.data["release-date"])
offset = 0
total: list[Run] = []
print("Fetching", end="")
while True:
print(".", end="")
data = api.search(Run, {"game": game_id, "offset": offset, "max": 200, "offset": offset, "status": "verified"})
total += data
if len(data) < 200:
break
else:
offset += 200
if offset == 10000:
break # SRC's api breaks trying to fetch greater than 10000 elements - apiv2 may rectify this but is not ideal for this application, as it is per-category
# This may not be ideal for your application - explore `ManicJamie/speedruncompy` for what should be a working, albeit harder to use, api wrapper.
with open("output.csv", "w") as f:
writer = csv.writer(f)
writer.writerow([f"{game_id} released {game.data['release-date']}", "Primary time", "Date submitted"])
for run in total:
writer.writerow([run.data["id"], run.data["times"]["primary_t"], run.data["submitted"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment