Syntrex commited on
Commit
1eb1bcd
·
verified ·
1 Parent(s): 2a91e3a

Update data/schedule.py

Browse files
Files changed (1) hide show
  1. data/schedule.py +76 -45
data/schedule.py CHANGED
@@ -1,47 +1,78 @@
1
  from __future__ import annotations
2
 
3
- from datetime import datetime
4
- from typing import Any
5
-
6
- import pandas as pd
7
- import requests
8
-
9
- from config.settings import MLB_SCHEDULE_URL
10
-
11
-
12
- def fetch_schedule_for_date(date_str: str) -> pd.DataFrame:
13
- params = {
14
- "sportId": 1,
15
- "date": date_str,
16
- "hydrate": "linescore,team,venue",
17
- }
18
-
19
- response = requests.get(MLB_SCHEDULE_URL, params=params, timeout=30)
20
- response.raise_for_status()
21
- payload = response.json()
22
-
23
- rows: list[dict[str, Any]] = []
24
-
25
- for date_block in payload.get("dates", []):
26
- for game in date_block.get("games", []):
27
- teams = game.get("teams", {})
28
- away = teams.get("away", {})
29
- home = teams.get("home", {})
30
- venue = game.get("venue", {}) or {}
31
- status = game.get("status", {}) or {}
32
-
33
- rows.append(
34
- {
35
- "fetched_at": datetime.utcnow(),
36
- "game_id": str(game.get("gamePk", "")),
37
- "game_date": game.get("gameDate"),
38
- "status": status.get("detailedState", ""),
39
- "away_team": away.get("team", {}).get("name", ""),
40
- "home_team": home.get("team", {}).get("name", ""),
41
- "away_score": away.get("score"),
42
- "home_score": home.get("score"),
43
- "venue": venue.get("name", ""),
44
- }
45
- )
46
-
47
- return pd.DataFrame(rows)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from __future__ import annotations
2
 
3
+ import os
4
+
5
+ APP_TITLE = "WBC Analytics Assistant"
6
+ REFRESH_TTL_SECONDS = 30
7
+
8
+ DUCKDB_PATH = "data/wbc.duckdb"
9
+
10
+ DEFAULT_EDGE_THRESHOLD = 0.05
11
+ DEFAULT_CONFIDENCE_THRESHOLD = 0.70
12
+
13
+ # Official / public sources
14
+ WBC_SCHEDULE_PAGE_URL = "https://www.mlb.com/world-baseball-classic/schedule"
15
+ WBC_HOME_URL = "https://www.mlb.com/world-baseball-classic"
16
+ WBC_STATS_URL = "https://www.mlb.com/world-baseball-classic/stats"
17
+ WBC_STANDINGS_URL = "https://www.mlb.com/world-baseball-classic/standings"
18
+
19
+ # Baseball Savant WBC Statcast
20
+ WBC_STATCAST_SEARCH_URL = "https://baseballsavant.mlb.com/statcast-search-world-baseball-classic"
21
+ STATCAST_SEARCH_URL = "https://baseballsavant.mlb.com/statcast_search/csv"
22
+
23
+ # MLB enrichment / fallback
24
+ MLB_SCHEDULE_URL = "https://statsapi.mlb.com/api/v1/schedule"
25
+ MLB_TEAMS_URL = "https://statsapi.mlb.com/api/v1/teams"
26
+
27
+ # Weather
28
+ OPENWEATHER_URL = "https://api.openweathermap.org/data/2.5/weather"
29
+
30
+ # Odds
31
+ ODDS_SPORT_KEY = "baseball_mlb"
32
+ ODDS_BASE_URL = "https://api.the-odds-api.com/v4"
33
+ ODDS_REGIONS = "us"
34
+ ODDS_FEATURED_MARKETS = "h2h,spreads,totals"
35
+ ODDS_FORMAT = "american"
36
+
37
+ ODDS_API_KEY = os.getenv("ODDS_API_KEY", "")
38
+ OPENWEATHER_API_KEY = os.getenv("OPENWEATHER_API_KEY", "")
39
+
40
+ SUPPORTED_BOOKS = [
41
+ "DraftKings",
42
+ "FanDuel",
43
+ "BetMGM",
44
+ "Caesars",
45
+ "bet365",
46
+ "Pinnacle",
47
+ ]
48
+
49
+ WBC_2026_VENUES = {
50
+ "Hiram Bithorn Stadium": {"lat": 18.3982, "lon": -66.0600, "city": "San Juan"},
51
+ "Daikin Park": {"lat": 29.7573, "lon": -95.3555, "city": "Houston"},
52
+ "Tokyo Dome": {"lat": 35.7056, "lon": 139.7519, "city": "Tokyo"},
53
+ "loanDepot park": {"lat": 25.7781, "lon": -80.2197, "city": "Miami"},
54
+ }
55
+
56
+ WBC_TEAMS = [
57
+ "Australia",
58
+ "Brazil",
59
+ "Canada",
60
+ "China",
61
+ "Chinese Taipei",
62
+ "Colombia",
63
+ "Cuba",
64
+ "Czech Republic",
65
+ "Dominican Republic",
66
+ "Great Britain",
67
+ "Israel",
68
+ "Italy",
69
+ "Japan",
70
+ "Korea",
71
+ "Mexico",
72
+ "Netherlands",
73
+ "Nicaragua",
74
+ "Panama",
75
+ "Puerto Rico",
76
+ "United States",
77
+ "Venezuela",
78
+ ]