This commit is contained in:
doms9 2025-10-15 10:53:54 -04:00
parent b110aee1e8
commit 00000d9ba6
11 changed files with 121 additions and 135 deletions

View file

@ -1,4 +1,5 @@
import re
from functools import partial
from pathlib import Path
from urllib.parse import urljoin
@ -26,7 +27,7 @@ async def process_event(
r = await client.get(url)
r.raise_for_status()
except Exception as e:
log.error(f'URL {url_num}) Failed to fetch "{url}"\n{e}')
log.error(f'URL {url_num}) Failed to fetch "{url}": {e}')
return
valid_m3u8 = re.compile(
@ -55,15 +56,15 @@ async def get_events(client: httpx.AsyncClient) -> list[dict[str, str]]:
events = []
for card in soup.css("div.container div.card"):
sport = card.css_first("h5.card-title").text(strip=True)
name = card.css_first("p.card-text").text(strip=True)
link = card.css_first("a.btn.btn-primary")
if not (href := link.attrs.get("href")):
continue
sport = card.css_first("h5.card-title").text(strip=True)
name = card.css_first("p.card-text").text(strip=True)
events.append(
{
"sport": sport,
@ -90,8 +91,10 @@ async def scrape(client: httpx.AsyncClient) -> None:
now = Time.now().timestamp()
for i, ev in enumerate(events, start=1):
handler = partial(process_event, client=client, url=ev["link"], url_num=i)
url = await network.safe_process(
lambda: process_event(client, url=ev["link"], url_num=i),
handler,
url_num=i,
log=log,
timeout=10,