Update scraper/scraper.py
All checks were successful
Build & Push Football Docker Images / build-push-update (push) Successful in 7s
All checks were successful
Build & Push Football Docker Images / build-push-update (push) Successful in 7s
Missing today game fix! The key fix for today — use dt.date() < now.date() instead of dt < now so today's date is NOT considered past.
This commit is contained in:
@@ -122,14 +122,16 @@ def scrape() -> list[dict]:
|
|||||||
opponent = away if is_home else home
|
opponent = away if is_home else home
|
||||||
opponent_logo = away_logo if is_home else home_logo
|
opponent_logo = away_logo if is_home else home_logo
|
||||||
|
|
||||||
# ── Score vs time ──────────────────────────────
|
# ── Score vs time ──────────────────────────────────────────────────
|
||||||
score_str = None
|
score_str = None
|
||||||
time_str = "TBD"
|
time_str = "TBD"
|
||||||
if is_past:
|
if is_past:
|
||||||
if re.match(r"\d+\s*-\s*\d+", mid_text):
|
# Extract just the score digits, ignore leg/aggregate text
|
||||||
score_str = mid_text.replace(" ", "")
|
score_match = re.search(r"(\d+)\s*-\s*(\d+)", mid_text)
|
||||||
|
if score_match:
|
||||||
|
score_str = f"{score_match.group(1)}-{score_match.group(2)}"
|
||||||
else:
|
else:
|
||||||
continue # skip if no valid score
|
continue
|
||||||
else:
|
else:
|
||||||
time_str = mid_text if mid_text not in ("", "TBD") else "TBD"
|
time_str = mid_text if mid_text not in ("", "TBD") else "TBD"
|
||||||
|
|
||||||
@@ -142,14 +144,13 @@ def scrape() -> list[dict]:
|
|||||||
try:
|
try:
|
||||||
dt = datetime.strptime(f"{date_text} {year}", fmt)
|
dt = datetime.strptime(f"{date_text} {year}", fmt)
|
||||||
dt = dt.replace(tzinfo=PT_TZ)
|
dt = dt.replace(tzinfo=PT_TZ)
|
||||||
|
|
||||||
if is_past:
|
if is_past:
|
||||||
# Past matches: if date is in the future, use previous year
|
if dt.date() > now.date():
|
||||||
if dt > now:
|
|
||||||
dt = dt.replace(year=year - 1)
|
dt = dt.replace(year=year - 1)
|
||||||
else:
|
else:
|
||||||
# Future matches: if date is in the past, use next year
|
# Use date() comparison so today's unplayed games stay as future
|
||||||
if dt < now:
|
if dt.date() < now.date():
|
||||||
dt = dt.replace(year=year + 1)
|
dt = dt.replace(year=year + 1)
|
||||||
break
|
break
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
Reference in New Issue
Block a user