This commit is contained in:
doms9 2025-11-11 17:16:10 -05:00
parent ceea4f7f5b
commit 00000d91dc
6 changed files with 28 additions and 21 deletions

View file

@ -45,7 +45,7 @@ async def main() -> None:
tasks = [
asyncio.create_task(fawa.scrape(network.client)),
#asyncio.create_task(fstv.scrape(network.client)),
# asyncio.create_task(fstv.scrape(network.client)),
asyncio.create_task(lotus.scrape(network.client)),
asyncio.create_task(pixel.scrape(network.client)),
asyncio.create_task(ppv.scrape(network.client)),

View file

@ -85,7 +85,7 @@ async def get_events(
sport = pattern.split(details)[0].strip()
event_time = Time.from_str(f"{now.date()} {match[0]} CET", "%Y-%m-%d %H:%M")
event_time = Time.from_str(f"{now.date()} {match[0]}", timezone="CET")
if not start_ts <= event_time <= end_ts:
continue

View file

@ -61,7 +61,7 @@ async def get_events(
events: list[dict[str, str]] = []
for info in api_data["days"]:
day = Time.from_str(info["day_et"], "%Y-%m-%d")
day = Time.from_str(info["day_et"])
if now.date() != day.date():
continue

View file

@ -63,7 +63,7 @@ async def get_events(
end_dt = now.delta(minutes=30)
for event in api_data["events"]:
event_dt = Time.from_str(f'{event["date"]} UTC', "%Y-%m-%dT%H:%M:%S.%fZ")
event_dt = Time.from_str(f'{event["date"]}', timezone="UTC")
if now.date() != event_dt.date():
continue

View file

@ -80,7 +80,7 @@ async def refresh_html_cache(
data_start = span.attributes["data-start"].rsplit(":", 1)[0]
event_dt = Time.from_str(f"{data_start} PST")
event_dt = Time.from_str(f"{data_start}", timezone="PST")
key = f"[{sport}] {event} (ROXIE)"

View file

@ -47,54 +47,61 @@ class Time(datetime):
dt = self.astimezone(self.ZONES[tzone])
return self.__class__.fromtimestamp(dt.timestamp(), tz=self.ZONES[tzone])
@classmethod
def _to_class_tz(cls, dt) -> "Time":
dt = dt.astimezone(cls.TZ)
return cls.fromtimestamp(dt.timestamp(), tz=cls.TZ)
@classmethod
def from_str(
cls,
s: str,
fmt: str | None = None,
timezone: str | None = None,
) -> "Time":
pattern = re.compile(rf"\b({"|".join(cls.ZONES.keys())})\b")
match = pattern.search(s)
tz = cls.ZONES.get(match[1]) if match else cls.TZ
cleaned_str = pattern.sub("", s).strip()
tz = cls.ZONES.get(timezone, cls.TZ)
if fmt:
dt = datetime.strptime(cleaned_str, fmt)
dt = datetime.strptime(s, fmt)
dt = tz.localize(dt)
else:
formats = [
"%B %d, %Y %H:%M %p",
"%B %d, %Y %I:%M %p",
"%B %d, %Y %I:%M:%S %p",
"%m/%d/%Y %I:%M %p",
"%B %d, %Y %H:%M",
"%B %d, %Y %H:%M:%S",
"%B %d, %Y %H:%M:%S %p",
"%Y-%m-%d",
"%Y-%m-%d %H:%M",
"%Y-%m-%d %H:%M:%S",
"%Y/%m/%d %H:%M",
"%Y/%m/%d %H:%M:%S",
"%m/%d/%Y %H:%M",
"%m/%d/%Y %H:%M:%S",
"%m/%d/%Y %I:%M %p",
"%Y/%m/%dT%H:%M:%S.%fZ",
"%Y-%m-%dT%H:%M:%S.%fZ",
"%a, %d %b %Y %H:%M:%S %z",
]
for frmt in formats:
try:
dt = datetime.strptime(cleaned_str, frmt)
dt = datetime.strptime(s, frmt)
break
except ValueError:
continue
else:
return cls.from_ts(Time.default_8())
if not dt.tzinfo:
dt = tz.localize(dt) if hasattr(tz, "localize") else dt.replace(tzinfo=tz)
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)
return cls._to_class_tz(dt)
class Leagues: