From 21ca98a4b681552fc6c00677ffa456c257b9c1f5 Mon Sep 17 00:00:00 2001 From: lulzette Date: Wed, 14 Dec 2022 21:59:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=B8=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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'):