- change caching process for select sites
This commit is contained in:
doms9 2026-04-16 17:42:28 -04:00
parent 6b209de1d8
commit 00000d9ef7
9 changed files with 138 additions and 212 deletions

View file

@ -50,7 +50,7 @@ async def process_event(url: str, url_num: int) -> str | None:
return m3u8.split("ip=")[0]
async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
async def get_events() -> list[dict[str, str]]:
events = []
if not (api_req := await network.request(API_URL, log=log)):
@ -70,9 +70,6 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
if (sport := event.get("category")) and sport == "Other":
sport = "Live Event"
if f"[{sport}] {name} ({TAG})" in cached_keys:
continue
events.append(
{
"sport": sport,
@ -85,20 +82,17 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
async def scrape() -> None:
cached_urls = CACHE_FILE.load()
if cached_urls := CACHE_FILE.load():
urls.update(cached_urls)
valid_urls = {k: v for k, v in cached_urls.items() if v["url"]}
log.info(f"Loaded {len(urls)} event(s) from cache")
valid_count = cached_count = len(valid_urls)
urls.update(valid_urls)
log.info(f"Loaded {cached_count} event(s) from cache")
return
log.info('Scraping from "https://streamtpnew.com"')
if events := await get_events(cached_urls.keys()):
log.info(f"Processing {len(events)} new URL(s)")
if events := await get_events():
log.info(f"Processing {len(events)} URL(s)")
now = Time.clean(Time.now())
@ -134,13 +128,11 @@ async def scrape() -> None:
cached_urls[key] = entry
if url:
valid_count += 1
urls[key] = entry
log.info(f"Collected and cached {valid_count - cached_count} new event(s)")
log.info(f"Collected and cached {len(urls)} event(s)")
else:
log.info("No new events found")
log.info("No events found")
CACHE_FILE.write(cached_urls)