diff --git a/M3U8/scrapers/livetvsx.py b/M3U8/scrapers/livetvsx.py index 74112f0..1143e3e 100644 --- a/M3U8/scrapers/livetvsx.py +++ b/M3U8/scrapers/livetvsx.py @@ -209,7 +209,7 @@ async def get_events( events: list[dict[str, str]] = [] - now = Time.now() + now = Time.clean(Time.now()) start_dt = now.delta(minutes=-30) end_dt = now.delta(minutes=30) diff --git a/M3U8/scrapers/ppv.py b/M3U8/scrapers/ppv.py index 60f7993..481213b 100644 --- a/M3U8/scrapers/ppv.py +++ b/M3U8/scrapers/ppv.py @@ -133,7 +133,7 @@ async def get_events( events: list[dict[str, str]] = [] - now = Time.now() + now = Time.clean(Time.now()) start_dt = now.delta(minutes=-30) end_dt = now.delta(minutes=30) diff --git a/M3U8/scrapers/streameast.py b/M3U8/scrapers/streameast.py index 09dfab2..f35f590 100644 --- a/M3U8/scrapers/streameast.py +++ b/M3U8/scrapers/streameast.py @@ -102,8 +102,7 @@ async def get_events( soup = HTMLParser(r.text) events = [] - now = Time.now() - + now = Time.clean(Time.now()) start_dt = now.delta(minutes=-30) end_dt = now.delta(minutes=30) diff --git a/M3U8/scrapers/streamed.py b/M3U8/scrapers/streamed.py index ede0383..36928bd 100644 --- a/M3U8/scrapers/streamed.py +++ b/M3U8/scrapers/streamed.py @@ -134,8 +134,8 @@ async def get_events( HTML_CACHE.write(events) live = [] - now = Time.now() + now = Time.clean(Time.now()) start_ts = now.delta(minutes=-30).timestamp() end_ts = now.delta(minutes=30).timestamp() diff --git a/M3U8/scrapers/utils/caching.py b/M3U8/scrapers/utils/caching.py index dfb0f0e..b09a201 100644 --- a/M3U8/scrapers/utils/caching.py +++ b/M3U8/scrapers/utils/caching.py @@ -1,5 +1,4 @@ import json -from datetime import datetime from pathlib import Path from .config import Time @@ -12,14 +11,10 @@ class Cache: self.exp = exp self.now_ts = Time.now().timestamp() - @staticmethod - def clean(dt: datetime) -> float: - return dt.replace(second=0, microsecond=0).timestamp() - def is_fresh(self, entry: dict) -> bool: ts: float | int = entry.get("timestamp", 31496400) - dt_ts = self.clean(Time.from_ts(ts)) + dt_ts = Time.clean(Time.from_ts(ts)).timestamp() return self.now_ts - dt_ts < self.exp @@ -34,7 +29,7 @@ class Cache: ts: float | int = data.get("timestamp", 31496400) - dt_ts = self.clean(Time.from_ts(ts)) + dt_ts = Time.clean(Time.from_ts(ts)).timestamp() return data if self.is_fresh({"timestamp": dt_ts}) else {} diff --git a/M3U8/scrapers/utils/config.py b/M3U8/scrapers/utils/config.py index 729d929..859d6c3 100644 --- a/M3U8/scrapers/utils/config.py +++ b/M3U8/scrapers/utils/config.py @@ -26,6 +26,10 @@ class Time(datetime): new_dt = super().__add__(timedelta(**kwargs)) return self.__class__.fromtimestamp(new_dt.timestamp(), tz=new_dt.tzinfo) + def clean(self) -> "Time": + new_dt = super().replace(second=0, microsecond=0) + return self.__class__.fromtimestamp(new_dt.timestamp(), tz=new_dt.tzinfo) + @classmethod def from_str(cls, s: str, fmt: str | None = None) -> "Time": pattern = r"\b(ET|UTC|EST|EDT)\b"