фиксики1

This commit is contained in:
2026-04-24 19:56:24 +03:00
parent c9c6761303
commit 2c21bce9ed
5 changed files with 81 additions and 65 deletions

View File

@@ -19,13 +19,13 @@ TZ = ZoneInfo("Europe/Moscow")
MATCH_START_LEAD_MINUTES = 1
# Как часто обновлять live-матч
LIVE_MATCH_POLL_SECONDS = 60
LIVE_MATCH_POLL_SECONDS = 30
# Как часто проверять матчи дня
MATCHES_LOOP_SECONDS = 60
# Как часто обновлять турнирную таблицу
STANDINGS_LOOP_SECONDS = 60
STANDINGS_LOOP_SECONDS = 30
# Через сколько секунд между попытками после ошибки в worker
WORKER_ERROR_RETRY_SECONDS = 30
@@ -202,47 +202,25 @@ def parse_score(value: str) -> int | None:
def fetch_match_live_data(match_id: int) -> dict:
"""
Получение live-данных матча с сайта.
На вход получаешь ID матча, например:
{
"id": 123,
"external_id": "1069999",
"match_date": datetime(...),
"status": "scheduled",
"home_score": None,
"away_score": None,
"tour": "1 тур",
"season": "2025/2026",
"place": "...",
"date_raw": "...",
"score_add": None,
"home_team_id": 10,
"away_team_id": 11,
}
Должна вернуть dict минимум такого вида:
{
"status": "scheduled" | "live" | "finished",
"home_score": int | None,
"away_score": int | None,
}
Можно вернуть и больше полей, но scheduler использует только эти.
"""
html = fetch_html(f"https://wfl.rfs.ru/match/{match_id}")
soup = BeautifulSoup(html, "html.parser")
live = soup.find("section", class_="game game--future game--live js-game-live-label game--shadow game--progress")
if live:
scores = soup.find("div", class_="score__container").find_all("div", class_="score__item")
score1 = parse_score(scores[0].text) if len(scores) > 0 else None
score2 = parse_score(scores[2].text) if len(scores) > 2 else None
return {"status": "live", "home_score": score1, "away_score": score2}
raise NotImplementedError("Implement fetch_match_live_data(match_id) by yourself")
score_box = soup.find("div", class_="score__container")
if score_box:
scores = score_box.find_all("div", class_="score__item")
home = parse_score(scores[0].text) if len(scores) > 0 else None
away = parse_score(scores[2].text) if len(scores) > 2 else None
else:
home = None
away = None
live = soup.find("section", class_=lambda c: c and "game--live" in c)
if live:
return {"status": "live", "home_score": home, "away_score": away}
elif not live and home and away:
return {"status": "finished", "home_score": home, "away_score": away}
return {"status": "scheduled", "home_score": home, "away_score": away}
# =========================================================
# ЛОГИКА ЗАПУСКА WATCHER'ОВ