cache nulls from totalsportek
This commit is contained in:
doms9 2025-12-27 12:52:18 -05:00
parent 2240077021
commit 00000d9875
2 changed files with 29 additions and 22 deletions

View file

@ -108,9 +108,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")
@ -137,7 +139,6 @@ async def scrape() -> None:
log=log, log=log,
) )
if url:
sport, event, link = ( sport, event, link = (
ev["sport"], ev["sport"],
ev["event"], ev["event"],
@ -157,9 +158,14 @@ async def scrape() -> None:
"link": link, "link": link,
} }
urls[key] = cached_urls[key] = entry cached_urls[key] = entry
if new_count := len(cached_urls) - cached_count: if url:
valid_count += 1
urls[key] = entry
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:

View file

@ -304,6 +304,7 @@ async def scrape() -> None:
if url: if url:
valid_count += 1 valid_count += 1
urls[key] = entry urls[key] = entry
finally: finally: