From 00000d9f5658e146025fc852fa5bfbe8ba9088a2 Mon Sep 17 00:00:00 2001 From: doms9 <96013514+doms9@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:50:17 -0400 Subject: [PATCH] e --- M3U8/scrapers/listapreta.py | 27 ++++++++------------------- M3U8/scrapers/streamtpnew.py | 22 ++++++---------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/M3U8/scrapers/listapreta.py b/M3U8/scrapers/listapreta.py index b1a68846..09962850 100644 --- a/M3U8/scrapers/listapreta.py +++ b/M3U8/scrapers/listapreta.py @@ -8,9 +8,7 @@ urls: dict[str, dict[str, str | float]] = {} TAG = "LISTA" -CACHE_FILE = Cache(TAG, exp=10_800) - -API_FILE = Cache(f"{TAG}-api", exp=19_800) +CACHE_FILE = Cache(TAG, exp=19_800) API_URL = "https://listapreta.site/sports-widget/events.php" @@ -64,22 +62,13 @@ async def process_event(url: str, url_num: int) -> tuple[str | None, str | None] async def get_events(cached_keys: list[str]) -> list[dict[str, str]]: now = Time.clean(Time.now()) - if not (api_data := API_FILE.load(per_entry=False, index=-1)): - log.info("Refreshing API cache") - - api_data = [{"timestamp": now.timestamp()}] - - if r := await network.request(API_URL, log=log): - api_data: list[dict[str, str]] = r.json() - - api_data[-1]["timestamp"] = now.timestamp() - - API_FILE.write(api_data) - events = [] - start_dt = now.delta(minutes=-30) - end_dt = now.delta(minutes=30) + if not (api_req := await network.request(API_URL, log=log)): + return events + + elif not (api_data := api_req.json()): + return events for event in api_data: sport = event.get("sport") @@ -96,7 +85,7 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]: event_dt = Time.from_str(event["start"], timezone="UTC") - if not start_dt <= now <= end_dt: + if now.date() != event_dt.date(): continue if not (channels := event.get("channels")): @@ -111,7 +100,7 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]: "sport": sport, "event": event_name, "link": link, - "timestamp": event_dt.timestamp(), + "timestamp": now.timestamp(), } ) diff --git a/M3U8/scrapers/streamtpnew.py b/M3U8/scrapers/streamtpnew.py index 60220310..523985cc 100644 --- a/M3U8/scrapers/streamtpnew.py +++ b/M3U8/scrapers/streamtpnew.py @@ -13,8 +13,6 @@ TAG = "STP" CACHE_FILE = Cache(TAG, exp=19_800) -API_FILE = Cache(f"{TAG}-api", exp=19_800) - API_URL = "https://streamtpnew.com/eventos.json" @@ -53,22 +51,14 @@ async def process_event(url: str, url_num: int) -> str | None: async def get_events(cached_keys: list[str]) -> list[dict[str, str]]: - now = Time.clean(Time.now()) - - if not (api_data := API_FILE.load(per_entry=False, index=-1)): - log.info("Refreshing API cache") - - api_data = [{"timestamp": now.timestamp()}] - - if r := await network.request(API_URL, log=log): - api_data: list[dict[str, str]] = r.json() - - api_data[-1]["timestamp"] = now.timestamp() - - API_FILE.write(api_data) - events = [] + if not (api_req := await network.request(API_URL, log=log)): + return events + + elif not (api_data := api_req.json()): + return events + for event in api_data: name = event.get("title")