Navigation Menu

Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Extracting all runs from a game #11

Closed
tiagocabaco opened this issue Jun 26, 2018 · 2 comments
Closed

Extracting all runs from a game #11

tiagocabaco opened this issue Jun 26, 2018 · 2 comments

Comments

@tiagocabaco
Copy link

Hello,

I am trying to gather data for a statistical modeling project. However, I can seem to figure out how to extract all the run times, dates, users and category (any% , etc) from one single game. Could you provide an examples how to do it?

Might be a very basic question but I am not that familiar with python syntax.

Thank you,

Tiago

@blha303
Copy link
Owner

blha303 commented Jun 27, 2018

Hey Tiago, it's a fairly complex thing to get all runs from a particular game, as there's a lot of categories and variables runs could be hidden under. I made a bug fix update to srcomapi while figuring out the below code, please update.

from srcomapi import SpeedrunCom, datatypes as dt
api = SpeedrunCom()
api.debug = 1
game = api.search(dt.Game, {"name": "super mario sunshine"})[0]
sms_runs = {}
for category in game.categories:
  if not category.name in sms_runs:
    sms_runs[category.name] = {}
  if category.type == 'per-level':
    for level in game.levels:
      sms_runs[category.name][level.name] = dt.Leaderboard(api, data=api.get("leaderboards/{}/level/{}/{}?embed=variables".format(game.id, level.id, category.id)))
  else:
    sms_runs[category.name] = dt.Leaderboard(api, data=api.get("leaderboards/{}/category/{}?embed=variables".format(game.id, category.id)))

It will show each url as it accesses it, I added this as otherwise there would be no feedback that it's working. When it's complete the sms_runs dictionary will contain all records from all categories, levels and variables (subsections). You can access a run object with sms_runs["category name"].runs[0]["run"], each run has .date, .level, .players, .times, some may have .splits or .videos. Please let me know if any further info is needed, and thanks for using srcomapi ^_^

@SDuranNebreda
Copy link

How are obsolete runs stored?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants