From ba3b7ad2f3cc5e645a62167b8c247fbb98d57fa8 Mon Sep 17 00:00:00 2001 From: Lulzette Date: Thu, 22 Jul 2021 23:04:09 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=81?= =?UTF-8?q?=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B4=D0=B5=D0=BC=D0=BE=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=20=D0=B8=20=D1=87=D1=83=D1=82=D1=8C=20=D0=BE=D0=BF?= =?UTF-8?q?=D1=82=D0=B8=D0=BC=D0=B8=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- daemon.py | 18 +++++++++++++----- requirements.txt | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/daemon.py b/daemon.py index 9c580b4..884d4ad 100644 --- a/daemon.py +++ b/daemon.py @@ -8,6 +8,11 @@ import os from threading import Thread import json import config_python +import schedule +from twitch import TwitchClient +import subprocess +import time + locked_streams = list() @@ -47,7 +52,6 @@ def recorder(i): print("Записываем стрим %s\n" % i) # FIXME: пофиксить абсолютный путь cmdline = ["youtube-dl","https://twitch.tv/"+i] - import subprocess # Не хочу делать тут проверку на существование "youtube-dl" в $PATH s = subprocess.call(cmdline, stdout=subprocess.DEVNULL) print("Запись стрима %s закончена\n" % i) @@ -55,13 +59,14 @@ def recorder(i): os.system("rm "+path+"/pid") print("lock файл удален") -def checkAlive(streamers, client_id): +def checkAlive(): + streamers = config_python.streamers + client_id = config_python.twitchid ''' 1. Проверка на наличие стрима 1.1 Если нет - удалить lock файл, если он есть 1.2 Если есть - создать lock файл, запустить записывалку ''' - from twitch import TwitchClient client = TwitchClient(client_id=client_id) for i in streamers: # Путь до диры со стримами @@ -93,5 +98,8 @@ def removeOldStreams(): pass if __name__ == "__main__": - if not checkTools(): exit() - checkAlive(config_python.streamers, config_python.twitchid) + # if not checkTools(): exit() + schedule.every(config_python.period).minutes.do(checkAlive) + while True: + schedule.run_pending() + time.sleep(1) diff --git a/requirements.txt b/requirements.txt index a757172..7c433f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ youtube-dl==2021.4.17 -python-twitch-client==0.7.1 \ No newline at end of file +python-twitch-client==0.7.1 +schedule \ No newline at end of file