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