поправил логирование внутри тредов
This commit is contained in:
26
get_data.py
26
get_data.py
@@ -33,8 +33,8 @@ if not os.path.exists("logs"):
|
|||||||
os.makedirs("logs")
|
os.makedirs("logs")
|
||||||
|
|
||||||
telegram_bot_token = "7639240596:AAH0YtdQoWZSC-_R_EW4wKAHHNLIA0F_ARY"
|
telegram_bot_token = "7639240596:AAH0YtdQoWZSC-_R_EW4wKAHHNLIA0F_ARY"
|
||||||
# TELEGRAM_CHAT_ID = 228977654
|
telegram_chat_id = 228977654
|
||||||
telegram_chat_id = -4803699526
|
# telegram_chat_id = -4803699526
|
||||||
log_config = {
|
log_config = {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"handlers": {
|
"handlers": {
|
||||||
@@ -296,19 +296,30 @@ def stop_offline_threads():
|
|||||||
|
|
||||||
# Функция запускаемая в потоках
|
# Функция запускаемая в потоках
|
||||||
def get_data_from_API(
|
def get_data_from_API(
|
||||||
name: str, url: str, quantity: float, stop_event: threading.Event
|
name: str, url: str, sleep_time: float, stop_event: threading.Event
|
||||||
):
|
):
|
||||||
if quantity <= 0:
|
|
||||||
raise ValueError("quantity must be > 0")
|
|
||||||
|
|
||||||
sleep_time = 1.0 / quantity # это и есть "раз в N секунд"
|
|
||||||
|
|
||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
start = time.time()
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
value = requests.get(url, timeout=5).json()
|
value = requests.get(url, timeout=5).json()
|
||||||
|
except json.JSONDecodeError as json_err:
|
||||||
|
logger.warning(f"[{name}] Ошибка парсинга JSON: {json_err}")
|
||||||
|
value = {"error": f"JSON decode error: {json_err}"}
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
logger.warning(f"[{name}] Таймаут при запросе {url}")
|
||||||
|
value = {"error": "timeout"}
|
||||||
|
except requests.exceptions.RequestException as req_err:
|
||||||
|
logger.warning(f"[{name}] Ошибка запроса: {req_err}")
|
||||||
|
value = {"error": str(req_err)}
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
logger.warning(f"[{name}] Неизвестная ошибка: {ex}")
|
||||||
value = {"error": str(ex)}
|
value = {"error": str(ex)}
|
||||||
|
|
||||||
|
# Проверяем, нет ли явного статуса ошибки в JSON
|
||||||
|
if isinstance(value, dict) and str(value.get("status", "")).lower() in ("error", "fail", "no-status"):
|
||||||
|
logger.warning(f"[{name}] API вернул статус '{value.get('status')}'")
|
||||||
|
|
||||||
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
||||||
results_q.put({"source": name, "ts": ts, "data": value})
|
results_q.put({"source": name, "ts": ts, "data": value})
|
||||||
logger.debug(f"[{ts}] name: {name}, status: {value.get('status', 'no-status')}")
|
logger.debug(f"[{ts}] name: {name}, status: {value.get('status', 'no-status')}")
|
||||||
@@ -1622,7 +1633,6 @@ def add_data_for_teams(new_data):
|
|||||||
|
|
||||||
total_age += player["age"]
|
total_age += player["age"]
|
||||||
total_height += player["height"]
|
total_height += player["height"]
|
||||||
|
|
||||||
total_points = points_start + points_bench
|
total_points = points_start + points_bench
|
||||||
points_start_pro = (
|
points_start_pro = (
|
||||||
f"{round(points_start * 100 / total_points)}%" if total_points else "0%"
|
f"{round(points_start * 100 / total_points)}%" if total_points else "0%"
|
||||||
|
|||||||
Reference in New Issue
Block a user