update streamhub caching
This commit is contained in:
doms9 2026-01-02 15:42:36 -05:00
parent 501a8d2847
commit 00000d9cd4

View file

@ -135,9 +135,11 @@ async def get_events(cached_keys: list[str]) -> list[dict[str, str]]:
async def scrape() -> None: async def scrape() -> None:
cached_urls = CACHE_FILE.load() cached_urls = CACHE_FILE.load()
cached_count = len(cached_urls) valid_urls = {k: v for k, v in cached_urls.items() if v["url"]}
urls.update(cached_urls) valid_count = cached_count = len(valid_urls)
urls.update(valid_urls)
log.info(f"Loaded {cached_count} event(s) from cache") log.info(f"Loaded {cached_count} event(s) from cache")
@ -169,7 +171,6 @@ async def scrape() -> None:
log=log, log=log,
) )
if url:
sport, event, logo, link, ts = ( sport, event, logo, link, ts = (
ev["sport"], ev["sport"],
ev["event"], ev["event"],
@ -191,12 +192,17 @@ async def scrape() -> None:
"link": link, "link": link,
} }
urls[key] = cached_urls[key] = entry cached_urls[key] = entry
if url:
valid_count += 1
urls[key] = entry
finally: finally:
await browser.close() await browser.close()
if new_count := len(cached_urls) - cached_count: if new_count := valid_count - cached_count:
log.info(f"Collected and cached {new_count} new event(s)") log.info(f"Collected and cached {new_count} new event(s)")
else: else: