сделано логирование

This commit is contained in:
2025-11-01 12:17:50 +03:00
parent 10e001b1e0
commit f1ee9d073a

View File

@@ -81,8 +81,6 @@ logger = logging.getLogger(__name__)
logger.handlers[2].formatter.use_emoji = True
LEAGUE = args.league
TEAM = args.team
LANG = args.lang
@@ -418,7 +416,7 @@ def results_consumer():
# матч ЗАКОНЧЕН → гасим live и включаем offline
if any(m in raw_ls_status_low for m in finished_markers):
print("[status] match finished → switch to OFFLINE")
logger.info("[status] match finished → switch to OFFLINE")
if (
GAME_START_DT
and GAME_START_DT.date() == datetime.now().date()
@@ -435,14 +433,16 @@ def results_consumer():
"online" in raw_ls_status_low or "live" in raw_ls_status_low
):
if globals().get("STATUS") not in ["live", "live_soon"]:
print(
logger.info(
"[status] match became LIVE → switch to LIVE threads"
)
globals()["STATUS"] = "live"
start_live_threads(SEASON, GAME_ID)
except Exception as e:
print("results_consumer: live-status postprocess error:", e)
logger.warning(
"results_consumer: live-status postprocess error:", e
)
else:
if source == "game":
@@ -471,7 +471,7 @@ def results_consumer():
}
else:
# 👉 уже есть какой-то game — неполным НЕ затираем
print(
logger.debug(
"results_consumer: got partial game, keeping previous one"
)
@@ -485,7 +485,7 @@ def results_consumer():
# ... остальная обработка ...
except Exception as e:
print("results_consumer error:", repr(e))
logger.warning("results_consumer error:", repr(e))
continue
@@ -502,9 +502,6 @@ def get_items(data: dict) -> list:
return None
from datetime import datetime
def pick_game_for_team(calendar_json):
"""
Возвращает:
@@ -599,7 +596,7 @@ async def lifespan(app: FastAPI):
season = now.year + 1
else:
season = now.year
print("не удалось получить последний сезон.")
logger.info("не удалось получить последний сезон.")
SEASON = season
# 2. берём календарь
@@ -608,7 +605,7 @@ async def lifespan(app: FastAPI):
URLS["calendar"].format(host=HOST, league=LEAGUE, season=season, lang=LANG)
).json()
except Exception as ex:
print(f"не получилось проверить работу API. код ошибки: {ex}")
logger.error(f"не получилось проверить работу API. код ошибки: {ex}")
# тут можно вообще не запускать сервер, но оставим как есть
calendar = None
@@ -620,6 +617,10 @@ async def lifespan(app: FastAPI):
GAME_START_DT = game_dt
GAME_TODAY = is_today
logger.info(
f"\nЛига: {LEAGUE}\nСезон: {season}\nКоманда: {TEAM}\nGame ID: {game_id}"
)
# 4. запускаем "длинные" потоки (они у тебя и так всегда)
thread_result_consumer = threading.Thread(
target=results_consumer,
@@ -846,9 +847,8 @@ async def status(request: Request):
# ✳️ сортируем latest_data в нужном порядке
sort_order = ["game", "live-status", "box-score", "play-by-play"]
sorted_keys = (
[k for k in sort_order if k in latest_data] +
sorted([k for k in latest_data if k not in sort_order])
sorted_keys = [k for k in sort_order if k in latest_data] + sorted(
[k for k in latest_data if k not in sort_order]
)
data = {
@@ -1823,4 +1823,6 @@ async def live_status():
if __name__ == "__main__":
uvicorn.run("get_data:app", host="0.0.0.0", port=8000, reload=True, log_level="critical")
uvicorn.run(
"get_data:app", host="0.0.0.0", port=8000, reload=True, log_level="critical"
)