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
Date parser is assigning wrong year. Fix in scrapper.py — smarter year assignment
This commit is contained in:
@@ -133,16 +133,23 @@ def scrape() -> list[dict]:
|
||||
else:
|
||||
time_str = mid_text if mid_text not in ("", "TBD") else "TBD"
|
||||
|
||||
# ── Parse date ─────────────────────────────────
|
||||
# ── Parse date ─────────────────────────────────────────────────────
|
||||
dt = None
|
||||
year = datetime.now(PT_TZ).year
|
||||
now = datetime.now(PT_TZ)
|
||||
year = now.year
|
||||
|
||||
for fmt in ("%a, %b %d %Y", "%A, %B %d %Y"):
|
||||
try:
|
||||
dt = datetime.strptime(f"{date_text} {year}", fmt)
|
||||
dt = dt.replace(tzinfo=PT_TZ)
|
||||
now = datetime.now(PT_TZ)
|
||||
# roll year forward for future dates that wrap
|
||||
if not is_past and dt.month < now.month - 2:
|
||||
|
||||
if is_past:
|
||||
# Past matches: if date is in the future, use previous year
|
||||
if dt > now:
|
||||
dt = dt.replace(year=year - 1)
|
||||
else:
|
||||
# Future matches: if date is in the past, use next year
|
||||
if dt < now:
|
||||
dt = dt.replace(year=year + 1)
|
||||
break
|
||||
except ValueError:
|
||||
|
||||
Reference in New Issue
Block a user