Getting subcategories with the API
3 years ago
Lower Austria, Austria

I'm using the speedrun.com API for my discord server. It takes the records from each category of the game and then displaysthe 3 fastest runs of each category in the "leaderboard" channel. This works fine, but it doesn't work for games with subcategories, in this case speedrun.com/gbt. You can see that Any% has the inbounds, out of bounds and pauseless subcategories. My code will get the top3 runs for any% out of bounds, since it is the fastest category.

I'm using python I get the game info like this: game = api.search(srcomapi.datatypes.Game, {"name": name})[0]

and then I loop though the categories like this: for category in game.categories:

This will only include the main categories. Does anyone have an idea?

Canada

Subcategories are not categories, they are variables. Variables all have an 'is-subcategory' value. https://github.com/speedruncomorg/api/blob/master/version1/variables.md

Edited by the author 3 years ago
Avasam likes this
Israel

As ShikenNuggets said, subcategories are not categories, but variables set as sub-categories. By glancing over the API documentation, I think the best course of action is:

First, search for the relevant variables for you in the game.variables, and get their ID and possible values. Note that in "Grey-box testing", you have different sub-category variables for each category, and one category without a sub-category.

Then, instead of searching through the game.categories.records (because that search ignore variables), search instead through the runs on the site. I don't know how you write it in the code itself, but the relevant function is here: https://github.com/speedruncomorg/api/blob/master/version1/runs.md#get-runs

You filter the runs by adding query parameters for the game and category (for each category), then for the relevant sub-categories you filter the results again by checking the relevant variable. After that you take the top 3 runs with the fastest times for each category/sub-category combination.

Edited by the author 3 years ago
Gaming_64 and Avasam like this