This commit is contained in:
doms9 2025-12-16 20:39:52 -05:00
parent ad80c3c982
commit 00000d998e
2 changed files with 51 additions and 59 deletions

View file

@ -141,7 +141,7 @@ async def get_events(
live = [] live = []
start_ts = now.delta(minutes=-30).timestamp() start_ts = now.delta(hours=-1).timestamp()
end_ts = now.delta(minutes=5).timestamp() end_ts = now.delta(minutes=5).timestamp()
for k, v in events.items(): for k, v in events.items():
@ -158,9 +158,8 @@ async def get_events(
async def scrape(client: httpx.AsyncClient) -> None: async def scrape(client: httpx.AsyncClient) -> None:
cached_urls = CACHE_FILE.load() cached_urls = CACHE_FILE.load()
valid_urls = {k: v for k, v in cached_urls.items() if v["url"]} cached_count = len(cached_urls)
valid_count = cached_count = len(valid_urls) urls.update(cached_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")
@ -190,6 +189,7 @@ async def scrape(client: httpx.AsyncClient) -> 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"],
@ -211,15 +211,11 @@ async def scrape(client: httpx.AsyncClient) -> None:
"link": link, "link": link,
} }
cached_urls[key] = entry urls[key] = cached_urls[key] = entry
if url:
valid_count += 1
urls[key] = entry
await browser.close() await browser.close()
if new_count := valid_count - cached_count: if new_count := len(cached_urls) - 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:
log.info("No new events found") log.info("No new events found")

View file

@ -94,7 +94,7 @@ async def get_events(
events = [] events = []
start_dt = now.delta(minutes=-30) start_dt = now.delta(hours=-1)
end_dt = now.delta(minutes=5) end_dt = now.delta(minutes=5)
for stream_group in api_data: for stream_group in api_data:
@ -139,9 +139,8 @@ async def get_events(
async def scrape(client: httpx.AsyncClient) -> None: async def scrape(client: httpx.AsyncClient) -> None:
cached_urls = CACHE_FILE.load() cached_urls = CACHE_FILE.load()
valid_urls = {k: v for k, v in cached_urls.items() if v["url"]} cached_count = len(cached_urls)
valid_count = cached_count = len(valid_urls) urls.update(cached_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")
@ -170,6 +169,7 @@ async def scrape(client: httpx.AsyncClient) -> None:
log=log, log=log,
) )
if url:
sport, event, ts, link = ( sport, event, ts, link = (
ev["sport"], ev["sport"],
ev["event"], ev["event"],
@ -190,15 +190,11 @@ async def scrape(client: httpx.AsyncClient) -> None:
"link": link, "link": link,
} }
cached_urls[key] = entry urls[key] = cached_urls[key] = entry
if url:
valid_count += 1
urls[key] = entry
await browser.close() await browser.close()
if new_count := valid_count - cached_count: if new_count := len(cached_urls) - 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:
log.info("No new events found") log.info("No new events found")