логотипы каналов, тест 2

This commit is contained in:
2026-07-02 14:47:37 +03:00
parent e32fdcb74e
commit 03a68ee8ca
9 changed files with 130 additions and 72 deletions

View File

@@ -21,6 +21,7 @@ DEFAULT_PARSER_SOURCES = [
"calendar_type": "tours",
"logo_base_path": r"D:\Графика\ФУТБОЛ\Женская Суперлига 2026\Teams Logos",
"photo_base_path": r"D:\Графика\ФУТБОЛ\Женская Суперлига 2026\Photo",
"channel_logo_base_path": r"D:\Графика\ФУТБОЛ\Женская Суперлига 2026\Лого каналов",
"teams_url": "https://wfl.rfs.ru/tournament/1061879/teams",
"schedule_url": "https://wfl.rfs.ru/tournament/1061879/calendar?round_id=1117550&type=tours",
"standings_url": "https://wfl.rfs.ru/tournament/1061879/tables",
@@ -38,6 +39,7 @@ DEFAULT_PARSER_SOURCES = [
"calendar_type": "stages",
"logo_base_path": r"D:\Графика\ФУТБОЛ\Кубок России 2026\Teams Logos",
"photo_base_path": r"D:\Графика\ФУТБОЛ\Кубок России 2026\Photo",
"channel_logo_base_path": r"D:\Графика\ФУТБОЛ\ЖФЛ Кубок России 2026\Лого каналов",
"teams_url": "https://wfl.rfs.ru/tournament/1064908/teams",
"schedule_url": "https://wfl.rfs.ru/tournament/1064908/calendar?round_id=1125159&type=stages",
"standings_url": "https://wfl.rfs.ru/tournament/1064908/tables",
@@ -49,6 +51,15 @@ DEFAULT_PARSER_SOURCES = [
]
SOURCE_SELECT_SQL = """
SELECT key, title, tournament_id, round_id, season, calendar_type,
logo_base_path, photo_base_path, channel_logo_base_path,
teams_url, schedule_url, standings_url,
match_base_url, base_url, sort_order, is_active
FROM parser_sources
"""
def _row_to_source(row: tuple) -> dict[str, Any]:
return {
"key": row[0] or "",
@@ -59,13 +70,14 @@ def _row_to_source(row: tuple) -> dict[str, Any]:
"calendar_type": row[5] or "tours",
"logo_base_path": row[6] or "",
"photo_base_path": row[7] or "",
"teams_url": row[8] or "",
"schedule_url": row[9] or "",
"standings_url": row[10] or "",
"match_base_url": row[11] or "",
"base_url": row[12] or "https://wfl.rfs.ru",
"sort_order": row[13] or 0,
"is_active": bool(row[14]),
"channel_logo_base_path": row[8] or "",
"teams_url": row[9] or "",
"schedule_url": row[10] or "",
"standings_url": row[11] or "",
"match_base_url": row[12] or "",
"base_url": row[13] or "https://wfl.rfs.ru",
"sort_order": row[14] or 0,
"is_active": bool(row[15]),
}
@@ -94,6 +106,7 @@ def ensure_project_settings_tables() -> None:
calendar_type VARCHAR(50) NOT NULL DEFAULT 'tours',
logo_base_path TEXT,
photo_base_path TEXT,
channel_logo_base_path TEXT,
teams_url TEXT,
schedule_url TEXT,
standings_url TEXT,
@@ -107,6 +120,7 @@ def ensure_project_settings_tables() -> None:
"""
)
cur.execute("ALTER TABLE parser_sources ADD COLUMN IF NOT EXISTS photo_base_path TEXT;")
cur.execute("ALTER TABLE parser_sources ADD COLUMN IF NOT EXISTS channel_logo_base_path TEXT;")
for key, value in DEFAULT_APP_SETTINGS.items():
cur.execute(
@@ -122,25 +136,12 @@ def ensure_project_settings_tables() -> None:
cur.execute(
"""
INSERT INTO parser_sources (
key,
title,
tournament_id,
round_id,
season,
calendar_type,
logo_base_path,
photo_base_path,
teams_url,
schedule_url,
standings_url,
match_base_url,
base_url,
sort_order,
is_active,
created_at,
updated_at
key, title, tournament_id, round_id, season, calendar_type,
logo_base_path, photo_base_path, channel_logo_base_path,
teams_url, schedule_url, standings_url, match_base_url, base_url,
sort_order, is_active, created_at, updated_at
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
ON CONFLICT (key) DO NOTHING;
""",
(
@@ -152,6 +153,7 @@ def ensure_project_settings_tables() -> None:
source["calendar_type"],
source["logo_base_path"],
source["photo_base_path"],
source["channel_logo_base_path"],
source["teams_url"],
source["schedule_url"],
source["standings_url"],
@@ -172,6 +174,15 @@ def ensure_project_settings_tables() -> None:
""",
(source.get("photo_base_path") or "", source["key"]),
)
cur.execute(
"""
UPDATE parser_sources
SET channel_logo_base_path = %s, updated_at = NOW()
WHERE key = %s
AND (channel_logo_base_path IS NULL OR TRIM(channel_logo_base_path) = '');
""",
(source.get("channel_logo_base_path") or "", source["key"]),
)
conn.commit()
except Exception:
conn.rollback()
@@ -223,26 +234,9 @@ def list_parser_sources_from_db(active_only: bool = True) -> list[dict[str, Any]
try:
with conn.cursor() as cur:
if active_only:
cur.execute(
"""
SELECT key, title, tournament_id, round_id, season, calendar_type,
logo_base_path, photo_base_path, teams_url, schedule_url, standings_url,
match_base_url, base_url, sort_order, is_active
FROM parser_sources
WHERE is_active = TRUE
ORDER BY sort_order ASC, title ASC;
"""
)
cur.execute(SOURCE_SELECT_SQL + " WHERE is_active = TRUE ORDER BY sort_order ASC, title ASC;")
else:
cur.execute(
"""
SELECT key, title, tournament_id, round_id, season, calendar_type,
logo_base_path, photo_base_path, teams_url, schedule_url, standings_url,
match_base_url, base_url, sort_order, is_active
FROM parser_sources
ORDER BY sort_order ASC, title ASC;
"""
)
cur.execute(SOURCE_SELECT_SQL + " ORDER BY sort_order ASC, title ASC;")
rows = cur.fetchall()
return [_row_to_source(row) for row in rows]
finally:
@@ -257,17 +251,7 @@ def get_parser_source_from_db(source_key: str) -> dict[str, Any] | None:
conn = get_connection()
try:
with conn.cursor() as cur:
cur.execute(
"""
SELECT key, title, tournament_id, round_id, season, calendar_type,
logo_base_path, photo_base_path, teams_url, schedule_url, standings_url,
match_base_url, base_url, sort_order, is_active
FROM parser_sources
WHERE key = %s
LIMIT 1;
""",
(source_key,),
)
cur.execute(SOURCE_SELECT_SQL + " WHERE key = %s LIMIT 1;", (source_key,))
row = cur.fetchone()
return _row_to_source(row) if row else None
finally:
@@ -292,6 +276,7 @@ def update_parser_source(source_key: str, values: dict[str, str]) -> None:
"calendar_type": "tours",
"logo_base_path": "",
"photo_base_path": "",
"channel_logo_base_path": "",
"teams_url": "",
"schedule_url": "",
"standings_url": "",
@@ -313,10 +298,11 @@ def update_parser_source(source_key: str, values: dict[str, str]) -> None:
"""
INSERT INTO parser_sources (
key, title, tournament_id, round_id, season, calendar_type,
logo_base_path, photo_base_path, teams_url, schedule_url, standings_url,
logo_base_path, photo_base_path, channel_logo_base_path,
teams_url, schedule_url, standings_url,
match_base_url, base_url, sort_order, is_active, created_at, updated_at
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
ON CONFLICT (key)
DO UPDATE SET
title = EXCLUDED.title,
@@ -326,6 +312,7 @@ def update_parser_source(source_key: str, values: dict[str, str]) -> None:
calendar_type = EXCLUDED.calendar_type,
logo_base_path = EXCLUDED.logo_base_path,
photo_base_path = EXCLUDED.photo_base_path,
channel_logo_base_path = EXCLUDED.channel_logo_base_path,
teams_url = EXCLUDED.teams_url,
schedule_url = EXCLUDED.schedule_url,
standings_url = EXCLUDED.standings_url,
@@ -344,6 +331,7 @@ def update_parser_source(source_key: str, values: dict[str, str]) -> None:
merged.get("calendar_type") or "tours",
merged.get("logo_base_path") or "",
merged.get("photo_base_path") or "",
merged.get("channel_logo_base_path") or "",
merged.get("teams_url") or "",
merged.get("schedule_url") or "",
merged.get("standings_url") or "",