Created
December 31, 2023 19:18
-
-
Save ManicJamie/c6e1be6fa5cc7c2cd2f095842788f98f to your computer and use it in GitHub Desktop.
Regional.py
This file contains 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
from speedruncompy import GetGameLeaderboard2, GetSearch, GetGameData | |
import json | |
game_id = "76rqmld8" | |
# Uncomment this area to get game by name | |
game_name = input("Enter game name:") | |
game = GetSearch(query=game_name, includeGames=True).perform()["gameList"][0] | |
game_id = game["id"] | |
gameData = GetGameData(gameId=game_id).perform() | |
categories = {c["name"]:c for c in gameData["categories"]} | |
print(list(categories.keys())) | |
while True: | |
catName = input("Enter the category name: ") | |
if catName not in categories: | |
print("Not found! Ensure you typed it correctly") | |
else: | |
break | |
category = categories[catName] | |
board = GetGameLeaderboard2(gameId=game_id, categoryId=category["id"]).perform_all() | |
regionCode = input("Enter region code (eg. 'us' or 'gb'): ") | |
players = {} # Only players from region | |
for p in board["playerList"]: | |
if str(p.get("areaId", "")).startswith(regionCode): | |
players[p["id"]] = p | |
regionBoard = [] | |
for run in board["runList"]: | |
for p in run["playerIds"]: | |
if p in players: | |
regionBoard.append(run) | |
break | |
with open("regionalBoard.json", "w") as f: | |
json.dump({"runList": regionBoard, "playerList": players}, f, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment