обновление для Кубка России
переделаны все парсеры на ссылки из базы
This commit is contained in:
@@ -5,6 +5,7 @@ from zoneinfo import ZoneInfo
|
||||
|
||||
from services.schedule_service import sync_matches
|
||||
from repositories.team_repository import get_team_external_id_by_name, get_team_id_by_external_id
|
||||
from parsers.parser_sources import get_parser_source
|
||||
|
||||
|
||||
MONTHS_RU = {
|
||||
@@ -24,11 +25,6 @@ MONTHS_RU = {
|
||||
|
||||
TZ = ZoneInfo("Europe/Moscow")
|
||||
|
||||
URL_SCHEDULE = (
|
||||
"https://wfl.rfs.ru/tournament/1061879/calendar?round_id=1117550&type=tours"
|
||||
)
|
||||
|
||||
SEASON = "2025/2026"
|
||||
|
||||
|
||||
def parse_russian_date(date_str: str, year: int | None = None) -> datetime:
|
||||
@@ -76,7 +72,7 @@ def safe_int(value: str | None) -> int | None:
|
||||
return int(value) if value.isdigit() else None
|
||||
|
||||
|
||||
def parse_schedule(html: str) -> list[dict]:
|
||||
def parse_schedule(html: str, season: str, source_key: str | None = None) -> list[dict]:
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
matches_data: list[dict] = []
|
||||
|
||||
@@ -151,10 +147,11 @@ def parse_schedule(html: str) -> list[dict]:
|
||||
"home_score": home_score,
|
||||
"away_score": away_score,
|
||||
"tour": tour,
|
||||
"season": SEASON,
|
||||
"season": season,
|
||||
"place": place,
|
||||
"date_raw": time_site,
|
||||
"score_add": score_add,
|
||||
"source_key": source_key,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -162,12 +159,18 @@ def parse_schedule(html: str) -> list[dict]:
|
||||
return matches_data
|
||||
|
||||
|
||||
def run_parser_schedule() -> None:
|
||||
html = fetch_html(URL_SCHEDULE)
|
||||
matches_data = parse_schedule(html)
|
||||
def run_parser_schedule(source_key: str | None = None) -> None:
|
||||
source = get_parser_source(source_key)
|
||||
print(f"[parser_schedule] Источник: {source['title']}")
|
||||
print(f"[parser_schedule] URL: {source['schedule_url']}")
|
||||
|
||||
html = fetch_html(source["schedule_url"])
|
||||
matches_data = parse_schedule(html, source["season"], source["key"])
|
||||
if matches_data:
|
||||
sync_matches(matches_data)
|
||||
print(f"[parser_schedule] Matches synced: {len(matches_data)}")
|
||||
else:
|
||||
print("[parser_schedule] Матчи не найдены")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user