diff --git a/main.py b/main.py index acd60b8..c7d5f84 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,8 @@ from termcolor import colored import os import sys import telebot +from datetime import datetime + streamer = config_python.streamer app_id = config_python.appid @@ -24,10 +26,18 @@ def stream_message_worker(data: dict): game_name = data['game_name'] stream_title = data['title'] stream_viewers = str(data['viewer_count']) + + # Считаем длительность стрима + # '2022-12-14T17:26:47Z' + stream_started_at = str(data['started_at']) + time_started = datetime.strptime(stream_started_at, "%Y-%m-%dT%H:%M:%SZ") + time_now = datetime.utcnow().replace(microsecond=0) + stream_duration = time_now - time_started # Готовим сообщение message = stream_title + '\n' + \ "Игра: " + game_name + '\n' + \ - "Зрителей: " + stream_viewers + "Зрителей: " + stream_viewers + '\n' + \ + "Длительность: " + str(stream_duration) log.info(message) # Если файл с айди существует, читаем его и редактируем сообщение из него if os.path.exists('msgid'):