-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_data.py
More file actions
45 lines (38 loc) · 1.52 KB
/
sync_data.py
File metadata and controls
45 lines (38 loc) · 1.52 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import os
import asyncio
from pathlib import Path
import pandas as pd
sys.path.append(str(Path(__file__).parent))
from backend.config import load_schedule_data_safe
from backend.main import _sync_scores_job
from backend.sqlite_store import upsert_game_scores
from backend.main import _fetch_remote_scores_for_date, _load_local_scores_for_date, _score_sync_dates
def sync_schedules():
print("Syncing schedules...")
backend_dir = Path(__file__).parent / "backend"
data_dir = backend_dir / "data"
for year in [2024, 2025]:
print(f"Fetching schedule for {year}...")
try:
df = load_schedule_data_safe(year)
if df is not None and not df.empty:
# Save to backend/data/
path1 = data_dir / f"Nfl_schedule_{year}.csv"
df.to_csv(path1, index=False)
print(f"Saved {year} schedule to {path1}")
# Save to backend/ (just in case)
path2 = backend_dir / f"Nfl_schedule_{year}.csv"
df.to_csv(path2, index=False)
print(f"Saved {year} schedule to {path2}")
else:
print(f"Failed to fetch or empty dataframe for {year}.")
except Exception as e:
print(f"Error fetching schedule for {year}: {e}")
async def run_sync_scores():
print("Syncing scores via job...")
await _sync_scores_job()
print("Score sync complete.")
if __name__ == "__main__":
sync_schedules()
asyncio.run(run_sync_scores())