This commit is contained in:
doms9 2025-10-01 14:56:15 -04:00
parent 7cabebb529
commit 00000d940b
4 changed files with 13 additions and 13 deletions

View file

@ -217,8 +217,6 @@ async def get_events(
if not (buffer := await fetch_xml_stream(url, ssl_ctx)):
return events
pub_date_format = "%a, %d %b %Y %H:%M:%S %z"
for _, elem in ET.iterparse(buffer, events=("end",)):
if elem.tag == "item":
title = elem.findtext("title") or ""
@ -231,7 +229,7 @@ async def get_events(
continue
try:
event_dt = Time.from_str(pub_date, pub_date_format)
event_dt = Time.from_str(pub_date)
except Exception:
elem.clear()
continue

View file

@ -134,13 +134,13 @@ async def get_events(
API_FILE.write(api_data)
for stream_group in api_data.get("streams", []):
sport = stream_group("category", [])
for stream_group in api_data["streams"]:
sport = stream_group["category"]
if sport == "24/7 Streams":
continue
for event in stream_group.get("streams", []):
for event in stream_group["streams"]:
name, start_ts, end_ts, logo, uri_name = (
event["name"],
event["starts_at"],

View file

@ -83,13 +83,13 @@ async def refresh_html_cache(client: httpx.AsyncClient, url: str) -> dict[str, s
soup = HTMLParser(r.text)
events = {}
now = Time.now().to_tz("EST")
now = Time.now()
for row in soup.css("div.wrap div.row"):
if not (date := row.css_first("div.date")):
continue
event_dt = Time.from_str(date.text(strip=True)).to_tz("EST")
event_dt = Time.from_str(date.text(strip=True))
if event_dt.date() != now.date():
continue
@ -134,10 +134,10 @@ async def get_events(
HTML_CACHE.write(events)
live = []
now = Time.now().to_tz("EST")
now = Time.now()
start_ts = now.delta(minutes=-30).to_tz("EST").timestamp()
end_ts = now.delta(minutes=30).to_tz("EST").timestamp()
start_ts = now.delta(minutes=-30).timestamp()
end_ts = now.delta(minutes=30).timestamp()
for k, v in events.items():
if cached_keys & {k}:

View file

@ -11,7 +11,7 @@ ZONES["EDT"] = ZONES["EST"] = ZONES["ET"]
class Time(datetime):
TZ = timezone.utc
TZ = ZONES["ET"]
@classmethod
def now(cls) -> "Time":
@ -42,6 +42,7 @@ class Time(datetime):
formats = [
"%Y-%m-%d %H:%M",
"%Y-%m-%d %H:%M:%S",
"%a, %d %b %Y %H:%M:%S %z",
]
for frmt in formats:
@ -53,6 +54,7 @@ class Time(datetime):
else:
return cls.from_ts(31496400)
if not dt.tzinfo:
dt = tz.localize(dt) if hasattr(tz, "localize") else dt.replace(tzinfo=tz)
return cls.fromtimestamp(dt.astimezone(cls.TZ).timestamp(), tz=cls.TZ)