Last active
February 22, 2026 17:30
-
-
Save shmup/59804900951a291cc515efa4f23c68c9 to your computer and use it in GitHub Desktop.
fetch replays for bar games
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
| #!/usr/bin/env -S uv run --script | |
| # /// script | |
| # dependencies = ["requests"] | |
| # /// | |
| """fetch recent bar replays with filters | |
| how this works: | |
| 1. search /replays with filters (preset, bots, map, players, etc) | |
| 2. get back a paginated list with ids, duration, map, and team summaries | |
| 3. pick a replay and hit /replays/:id for full detail (engine, game version, etc) | |
| """ | |
| from urllib.parse import quote | |
| import requests | |
| API = "https://api.bar-rts.com" | |
| DEMO_STORAGE = "https://storage.uk.cloud.ovh.net/v1/AUTH_10286efc0d334efd917d476d7183232e/BAR/demos" | |
| # filters | |
| PRESET = "duel" | |
| HAS_BOTS = "false" | |
| ENDED_NORMALLY = "true" | |
| PLAYERS = ["Flash"] # use [] for no player filtering | |
| MAPS = [] # use map scriptNames, e.g. ["Supreme Isthmus v5.3"] | |
| LIMIT = 1 | |
| def get_replays(**filters): | |
| params = {"page": 1, "limit": 10, **filters} | |
| resp = requests.get(f"{API}/replays", params=params) | |
| resp.raise_for_status() | |
| return resp.json() | |
| def get_replay(replay_id): | |
| resp = requests.get(f"{API}/replays/{replay_id}") | |
| resp.raise_for_status() | |
| return resp.json() | |
| if __name__ == "__main__": | |
| # tweak these filters however you want | |
| filters = { | |
| "preset": PRESET, | |
| "hasBots": HAS_BOTS, | |
| "endedNormally": ENDED_NORMALLY, | |
| "limit": LIMIT, | |
| } | |
| if PLAYERS: | |
| filters["players"] = PLAYERS | |
| if MAPS: | |
| filters["maps"] = MAPS | |
| results = get_replays(**filters) | |
| print(f"showing {len(results['data'])} replays\n") | |
| for r in results["data"]: | |
| mins = r["durationMs"] // 60000 | |
| map_name = r["Map"]["scriptName"] | |
| teams = r.get("AllyTeams", []) | |
| players = [] | |
| for team in teams: | |
| names = [p["name"] for p in team.get("Players", [])] | |
| players.append(" + ".join(names) if names else "?") | |
| matchup = " vs ".join(players) | |
| print(f" {r['id'][:12]} {mins:>3}min {map_name}") | |
| print(f" {matchup}") | |
| # grab full detail for the first one as an example | |
| if r == results["data"][0]: | |
| detail = get_replay(r["id"]) | |
| print(f" engine: {detail['engineVersion']}") | |
| print(f" game: {detail['gameVersion']}") | |
| print(f" download: {DEMO_STORAGE}/{quote(detail['fileName'])}") | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment