обновление для Кубка России
переделаны все парсеры на ссылки из базы
This commit is contained in:
@@ -1,27 +1,44 @@
|
||||
# services/vmix_json_service.py
|
||||
from db import get_connection
|
||||
from repositories.match_lineup_repository import get_match_lineup_for_vmix
|
||||
from parsers.parser_sources import build_empty_photo_path, build_logo_path, build_logo_variant_path, build_photo_path
|
||||
|
||||
|
||||
PHOTO_BASE_PATH = r"D:\Графика\ФУТБОЛ\Женская Суперлига 2026\Photo"
|
||||
EMPTY_PHOTO_PATH = PHOTO_BASE_PATH + r"\EMPTY.png"
|
||||
DEFAULT_PHOTO_BASE_PATH = r"D:\Графика\ФУТБОЛ\Женская Суперлига 2026\Photo"
|
||||
EMPTY_PHOTO_PATH = DEFAULT_PHOTO_BASE_PATH + r"\EMPTY.png"
|
||||
|
||||
|
||||
def build_generated_player_photo_path(team_name: str, last_name: str, first_name: str) -> str:
|
||||
return (
|
||||
PHOTO_BASE_PATH
|
||||
+ "\\"
|
||||
+ str(team_name or "")
|
||||
def _session_source_key(session_row) -> str | None:
|
||||
try:
|
||||
value = session_row[21]
|
||||
except Exception:
|
||||
value = None
|
||||
return str(value).strip() if value else None
|
||||
|
||||
|
||||
def build_generated_player_photo_path(
|
||||
team_name: str,
|
||||
last_name: str,
|
||||
first_name: str,
|
||||
source_key: str | None = None,
|
||||
) -> str:
|
||||
relative_file = (
|
||||
str(team_name or "").strip()
|
||||
+ "\\"
|
||||
+ (str(last_name or "") + " " + str(first_name or "")).strip()
|
||||
+ ".png"
|
||||
)
|
||||
return build_photo_path(source_key, relative_file)
|
||||
|
||||
|
||||
def resolve_player_photo(photo_enabled: bool, generated_photo: str) -> str:
|
||||
def resolve_player_photo(
|
||||
photo_enabled: bool,
|
||||
generated_photo: str,
|
||||
source_key: str | None = None,
|
||||
) -> str:
|
||||
if photo_enabled:
|
||||
return generated_photo
|
||||
return EMPTY_PHOTO_PATH
|
||||
return build_empty_photo_path(source_key) or EMPTY_PHOTO_PATH
|
||||
|
||||
|
||||
def _normalize_text(value) -> str:
|
||||
@@ -208,6 +225,7 @@ def resolve_player_photo_for_json(
|
||||
player: dict,
|
||||
generated_photo: str,
|
||||
fallback_team_id=None,
|
||||
source_key: str | None = None,
|
||||
) -> str:
|
||||
state = _find_player_photo_state(
|
||||
player_id=player.get("player_id") or player.get("id"),
|
||||
@@ -220,16 +238,24 @@ def resolve_player_photo_for_json(
|
||||
)
|
||||
|
||||
if state is not None:
|
||||
_photo, photo_enabled = state
|
||||
return resolve_player_photo(photo_enabled=photo_enabled, generated_photo=generated_photo)
|
||||
photo_value, photo_enabled = state
|
||||
resolved_photo = build_photo_path(source_key, photo_value) if photo_value else generated_photo
|
||||
return resolve_player_photo(
|
||||
photo_enabled=photo_enabled,
|
||||
generated_photo=resolved_photo,
|
||||
source_key=source_key,
|
||||
)
|
||||
|
||||
photo_value = player.get("photo") or ""
|
||||
resolved_photo = build_photo_path(source_key, photo_value) if photo_value else generated_photo
|
||||
return resolve_player_photo(
|
||||
photo_enabled=player.get("photo_enabled"),
|
||||
generated_photo=generated_photo,
|
||||
generated_photo=resolved_photo,
|
||||
source_key=source_key,
|
||||
)
|
||||
|
||||
|
||||
def build_lineup_json(match_id, home_team_id, away_team_id, name, team_a_name, team_b_name):
|
||||
def build_lineup_json(match_id, home_team_id, away_team_id, name, team_a_name, team_b_name, source_key=None):
|
||||
lineups = get_match_lineup_for_vmix(
|
||||
match_id=match_id,
|
||||
home_team_id=home_team_id,
|
||||
@@ -274,8 +300,10 @@ def build_lineup_json(match_id, home_team_id, away_team_id, name, team_a_name, t
|
||||
team_name=team_a_name if "home" in name else team_b_name,
|
||||
last_name=p.get("last_name", ""),
|
||||
first_name=p.get("first_name", ""),
|
||||
source_key=source_key,
|
||||
),
|
||||
fallback_team_id=fallback_team_id,
|
||||
source_key=source_key,
|
||||
),
|
||||
}
|
||||
)
|
||||
@@ -305,43 +333,16 @@ def get_vmix_match_info_by_token(session_token: str):
|
||||
|
||||
m.tour,
|
||||
ht.logo_path AS home_logo,
|
||||
REPLACE(at.logo_path, 'HOME', 'AWAY') AS away_logo,
|
||||
at.logo_path AS away_logo,
|
||||
ref1.referee_name AS referee1,
|
||||
ref2.referee_name AS referee2,
|
||||
ref3.referee_name AS referee3,
|
||||
ref4.referee_name AS referee4,
|
||||
|
||||
CASE
|
||||
WHEN ht.name ILIKE '%%динамо%%'
|
||||
THEN REPLACE(REPLACE(ht.logo_path, 'HOME\\', ''), 'Динамо', 'Динамо_Белый')
|
||||
WHEN ht.name ILIKE '%%зенит%%'
|
||||
THEN REPLACE(REPLACE(ht.logo_path, 'HOME\\', ''), 'Зенит', 'Зенит_Белый')
|
||||
ELSE REPLACE(ht.logo_path, 'HOME\\', '')
|
||||
END AS home_logo1,
|
||||
|
||||
CASE
|
||||
WHEN at.name ILIKE '%%динамо%%'
|
||||
THEN REPLACE(REPLACE(at.logo_path, 'HOME\\', ''), 'Динамо', 'Динамо_Белый')
|
||||
WHEN at.name ILIKE '%%зенит%%'
|
||||
THEN REPLACE(REPLACE(at.logo_path, 'HOME\\', ''), 'Зенит', 'Зенит_Белый')
|
||||
ELSE REPLACE(at.logo_path, 'HOME\\', '')
|
||||
END AS away_logo1,
|
||||
|
||||
CASE
|
||||
WHEN ht.name ILIKE '%%динамо%%'
|
||||
THEN REPLACE(REPLACE(ht.logo_path, 'HOME\\', ''), 'Динамо', 'Динамо_Синий')
|
||||
WHEN ht.name ILIKE '%%зенит%%'
|
||||
THEN REPLACE(REPLACE(ht.logo_path, 'HOME\\', ''), 'Зенит', 'Зенит_Синий')
|
||||
ELSE REPLACE(ht.logo_path, 'HOME\\', '')
|
||||
END AS home_logo2,
|
||||
|
||||
CASE
|
||||
WHEN at.name ILIKE '%%динамо%%'
|
||||
THEN REPLACE(REPLACE(at.logo_path, 'HOME\\', ''), 'Динамо', 'Динамо_Синий')
|
||||
WHEN at.name ILIKE '%%зенит%%'
|
||||
THEN REPLACE(REPLACE(at.logo_path, 'HOME\\', ''), 'Зенит', 'Зенит_Синий')
|
||||
ELSE REPLACE(at.logo_path, 'HOME\\', '')
|
||||
END AS away_logo2,
|
||||
ht.logo_path AS home_logo1,
|
||||
at.logo_path AS away_logo1,
|
||||
ht.logo_path AS home_logo2,
|
||||
at.logo_path AS away_logo2,
|
||||
|
||||
ht.city AS home_city,
|
||||
at.city AS away_city,
|
||||
@@ -350,7 +351,8 @@ def get_vmix_match_info_by_token(session_token: str):
|
||||
c1.amplua AS coach_amplua1,
|
||||
|
||||
TRIM(COALESCE(c2.name, '') || ' ' || COALESCE(c2.lastname, '')) AS coach_name2,
|
||||
c2.amplua AS coach_amplua2
|
||||
c2.amplua AS coach_amplua2,
|
||||
m.source_key AS source_key
|
||||
|
||||
FROM match_sessions ms
|
||||
JOIN matches m ON m.id = ms.match_id
|
||||
@@ -378,23 +380,33 @@ def get_vmix_match_info_by_token(session_token: str):
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(query, (session_token,))
|
||||
return cur.fetchone()
|
||||
row = cur.fetchone()
|
||||
|
||||
if not row:
|
||||
return None
|
||||
|
||||
row = list(row)
|
||||
source_key = row[30] if len(row) > 30 else None
|
||||
row[14] = build_logo_path(source_key, row[14])
|
||||
row[15] = build_logo_path(source_key, row[15])
|
||||
row[20] = build_logo_variant_path(source_key, row[20], "white")
|
||||
row[21] = build_logo_variant_path(source_key, row[21], "white")
|
||||
row[22] = build_logo_variant_path(source_key, row[22], "blue")
|
||||
row[23] = build_logo_variant_path(source_key, row[23], "blue")
|
||||
return tuple(row)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_vmix_standings(session_token: str):
|
||||
def get_vmix_standings(session_row):
|
||||
source_key = _session_source_key(session_row)
|
||||
season = session_row[11] if len(session_row) > 11 else None
|
||||
|
||||
query = """
|
||||
SELECT
|
||||
s.position,
|
||||
t.full_name,
|
||||
CASE
|
||||
WHEN t.full_name ILIKE '%%динамо%%'
|
||||
THEN REPLACE(REPLACE(t.logo_path, 'HOME\\', ''), 'Динамо', 'Динамо_Белый')
|
||||
WHEN t.full_name ILIKE '%%зенит%%'
|
||||
THEN REPLACE(REPLACE(t.logo_path, 'HOME\\', ''), 'Зенит', 'Зенит_Белый')
|
||||
ELSE REPLACE(t.logo_path, 'HOME\\', '')
|
||||
END AS logo,
|
||||
COALESCE(t.full_name, t.name) AS team_name,
|
||||
t.logo_path AS logo,
|
||||
s.played,
|
||||
s.wins,
|
||||
s.losses,
|
||||
@@ -404,35 +416,36 @@ def get_vmix_standings(session_token: str):
|
||||
s.team_id
|
||||
FROM standings s
|
||||
LEFT JOIN teams t ON s.team_id = t.id
|
||||
WHERE (%s IS NULL OR s.season = %s)
|
||||
ORDER BY s.position
|
||||
"""
|
||||
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(query, (session_token,))
|
||||
return cur.fetchall()
|
||||
cur.execute(query, (season, season))
|
||||
rows = cur.fetchall()
|
||||
|
||||
result = []
|
||||
for row in rows:
|
||||
row = list(row)
|
||||
row[2] = build_logo_variant_path(source_key, row[2], "white")
|
||||
result.append(tuple(row))
|
||||
return result
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_vmix_schedule(session_token: str):
|
||||
def get_vmix_schedule(session_row):
|
||||
source_key = _session_source_key(session_row)
|
||||
tour = session_row[10] if len(session_row) > 10 else None
|
||||
season = session_row[11] if len(session_row) > 11 else None
|
||||
source_filter = source_key or "SUPERLEAGUE"
|
||||
|
||||
query = """
|
||||
SELECT
|
||||
CASE
|
||||
WHEN t1.full_name ILIKE '%%динамо%%'
|
||||
THEN REPLACE(REPLACE(t1.logo_path, 'HOME\\', ''), 'Динамо', 'Динамо_Белый')
|
||||
WHEN t1.full_name ILIKE '%%зенит%%'
|
||||
THEN REPLACE(REPLACE(t1.logo_path, 'HOME\\', ''), 'Зенит', 'Зенит_Белый')
|
||||
ELSE REPLACE(t1.logo_path, 'HOME\\', '')
|
||||
END AS logo1,
|
||||
CASE
|
||||
WHEN t2.full_name ILIKE '%%динамо%%'
|
||||
THEN REPLACE(REPLACE(t2.logo_path, 'HOME\\', ''), 'Динамо', 'Динамо_Белый')
|
||||
WHEN t2.full_name ILIKE '%%зенит%%'
|
||||
THEN REPLACE(REPLACE(t2.logo_path, 'HOME\\', ''), 'Зенит', 'Зенит_Белый')
|
||||
ELSE REPLACE(t2.logo_path, 'HOME\\', '')
|
||||
END AS logo2,
|
||||
t1.logo_path AS logo1,
|
||||
t2.logo_path AS logo2,
|
||||
m.home_score,
|
||||
m.away_score,
|
||||
m.match_date,
|
||||
@@ -443,14 +456,24 @@ def get_vmix_schedule(session_token: str):
|
||||
LEFT JOIN teams t1 ON m.home_team_id = t1.id
|
||||
LEFT JOIN teams t2 ON m.away_team_id = t2.id
|
||||
WHERE m.tour = %s
|
||||
AND (%s IS NULL OR m.season = %s)
|
||||
AND COALESCE(m.source_key, %s) = %s
|
||||
ORDER BY m.match_date, m.id
|
||||
"""
|
||||
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(query, (session_token[10],))
|
||||
return cur.fetchall()
|
||||
cur.execute(query, (tour, season, season, source_filter, source_filter))
|
||||
rows = cur.fetchall()
|
||||
|
||||
result = []
|
||||
for row in rows:
|
||||
row = list(row)
|
||||
row[0] = build_logo_variant_path(source_key, row[0], "white")
|
||||
row[1] = build_logo_variant_path(source_key, row[1], "white")
|
||||
result.append(tuple(row))
|
||||
return result
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user