forked from broomhead/curlbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefresh_leagues.py
More file actions
29 lines (20 loc) · 1013 Bytes
/
Copy pathrefresh_leagues.py
File metadata and controls
29 lines (20 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Force-refresh the league cache (league_cache.json).
Use this to update the cache out-of-band so the live bot never has to block on
a site fetch. Run on a schedule, e.g. a daily cron / scheduled task:
docker compose run --rm curlbot python refresh_leagues.py
The bot also refreshes lazily on its own when the cache goes stale
(LEAGUE_CACHE_TTL, default 6h), so this script is optional — it just keeps the
file warm and moves the network cost off the request path.
"""
import asyncio
from league_client import get_cached_leagues, CACHE_PATH
async def main():
leagues = await get_cached_leagues(force=True)
active = [lg for lg in leagues if not lg.get("ended")]
print(f"Refreshed {CACHE_PATH}: {len(leagues)} leagues ({len(active)} active)")
for lg in active:
nd = lg.get("next_draw")
nxt = f"next {nd['weekday']} {nd['date']} {nd['time']}" if nd else "no upcoming draws"
print(f" • {lg.get('day')}: {lg.get('teams')} teams — {nxt}")
asyncio.run(main())