Spaces:
Build error
Build error
James McCool commited on
Commit ·
9ef68b1
1
Parent(s): cf5465e
Making sure that contest IDs are only from current day
Browse files- app.py +2 -1
- global_func/contest_pricing_api.py +31 -7
app.py
CHANGED
|
@@ -1493,7 +1493,8 @@ if selected_tab == 'Data Load':
|
|
| 1493 |
contest_options = st.session_state.get('pricing_contests', [])
|
| 1494 |
if contest_options:
|
| 1495 |
contest_labels = [
|
| 1496 |
-
f"{c
|
|
|
|
| 1497 |
for c in contest_options
|
| 1498 |
]
|
| 1499 |
contest_dropdown_options = ["None"] + contest_labels
|
|
|
|
| 1493 |
contest_options = st.session_state.get('pricing_contests', [])
|
| 1494 |
if contest_options:
|
| 1495 |
contest_labels = [
|
| 1496 |
+
f"{c.get('contest_date_display') or c.get('contest_date', '') or '—'} | {c['contest_name']} | "
|
| 1497 |
+
f"{c.get('game_type', '')} | ${int(c.get('prize_pool', 0)):,.0f}"
|
| 1498 |
for c in contest_options
|
| 1499 |
]
|
| 1500 |
contest_dropdown_options = ["None"] + contest_labels
|
global_func/contest_pricing_api.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
-
from datetime import datetime
|
| 2 |
-
from typing import Union
|
| 3 |
|
| 4 |
import pandas as pd
|
|
|
|
|
|
|
| 5 |
try:
|
| 6 |
from curl_cffi import requests as http_requests
|
| 7 |
USE_IMPERSONATE = True
|
|
@@ -20,6 +22,27 @@ SPORT_API_MAP = {
|
|
| 20 |
"MMA": "MMA",
|
| 21 |
}
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def _contest_type_matches(game_type: str, type_var: str) -> bool:
|
| 25 |
if type_var == "Showdown":
|
|
@@ -58,16 +81,17 @@ def fetch_contests_for_selection(sport_var: str, type_var: str) -> list[dict]:
|
|
| 58 |
continue
|
| 59 |
|
| 60 |
start_raw = contest.get("sd")
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
|
| 66 |
filtered.append(
|
| 67 |
{
|
| 68 |
"contest_name": name,
|
| 69 |
"contest_id": contest.get("id"),
|
| 70 |
-
"contest_date": contest_date,
|
|
|
|
| 71 |
"game_type": game_type,
|
| 72 |
"prize_pool": contest.get("po", 0),
|
| 73 |
}
|
|
|
|
| 1 |
+
from datetime import datetime, timezone
|
| 2 |
+
from typing import Optional, Tuple, Union
|
| 3 |
|
| 4 |
import pandas as pd
|
| 5 |
+
import pytz
|
| 6 |
+
|
| 7 |
try:
|
| 8 |
from curl_cffi import requests as http_requests
|
| 9 |
USE_IMPERSONATE = True
|
|
|
|
| 22 |
"MMA": "MMA",
|
| 23 |
}
|
| 24 |
|
| 25 |
+
# MLB / NBA / NHL: only list contests whose slate date is "today" in US/Eastern (excludes next-day slates).
|
| 26 |
+
_TODAY_SLATE_SPORTS = frozenset({"MLB", "NBA", "NHL"})
|
| 27 |
+
_EASTERN = pytz.timezone("US/Eastern")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _parse_sd_to_eastern_date_strings(start_raw) -> Tuple[Optional[str], Optional[str]]:
|
| 31 |
+
"""Return (YYYYMMDD, display YYYY-MM-DD) in US/Eastern from DK `sd` field, or (None, None)."""
|
| 32 |
+
if start_raw is None:
|
| 33 |
+
return None, None
|
| 34 |
+
try:
|
| 35 |
+
ts_ms = int(str(start_raw)[6:-2])
|
| 36 |
+
dt_utc = datetime.fromtimestamp(ts_ms / 1000.0, tz=timezone.utc)
|
| 37 |
+
dt_eastern = dt_utc.astimezone(_EASTERN)
|
| 38 |
+
return dt_eastern.strftime("%Y%m%d"), dt_eastern.strftime("%Y-%m-%d")
|
| 39 |
+
except Exception:
|
| 40 |
+
return None, None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _today_yyyymmdd_eastern() -> str:
|
| 44 |
+
return datetime.now(_EASTERN).strftime("%Y%m%d")
|
| 45 |
+
|
| 46 |
|
| 47 |
def _contest_type_matches(game_type: str, type_var: str) -> bool:
|
| 48 |
if type_var == "Showdown":
|
|
|
|
| 81 |
continue
|
| 82 |
|
| 83 |
start_raw = contest.get("sd")
|
| 84 |
+
contest_date, contest_date_display = _parse_sd_to_eastern_date_strings(start_raw)
|
| 85 |
+
if sport_var in _TODAY_SLATE_SPORTS:
|
| 86 |
+
if not contest_date or contest_date != _today_yyyymmdd_eastern():
|
| 87 |
+
continue
|
| 88 |
|
| 89 |
filtered.append(
|
| 90 |
{
|
| 91 |
"contest_name": name,
|
| 92 |
"contest_id": contest.get("id"),
|
| 93 |
+
"contest_date": contest_date or "",
|
| 94 |
+
"contest_date_display": contest_date_display or "",
|
| 95 |
"game_type": game_type,
|
| 96 |
"prize_pool": contest.get("po", 0),
|
| 97 |
}
|