-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrepeated_runner.py
30 lines (24 loc) · 891 Bytes
/
repeated_runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import time
from datetime import datetime
import telegram_send
run_script = "/home/frequensy/MosTransParser/moscow_tranport_stations/venv/bin/python3.9 " \
"/home/frequensy/MosTransParser/moscow_tranport_stations/main.py --stations " \
"/home/frequensy/MosTransParser/moscow_tranport_stations/uniq_stops.csv -d --proxy_file proxy.txt "
restart_tor = "sudo service tor reload"
def telelog(msg: str):
"""Log to telegram"""
print(f"{msg}")
telegram_send.send(messages=[msg])
sleep = True
while True:
t0 = time.time()
if sleep and (datetime.now().hour + 3) % 24 < 5:
telelog("sleep")
time.sleep(60 * 60)
try:
telelog(f"Started at {datetime.now()}")
os.system(run_script)
except:
telelog(f"Smth went wrong at {datetime.now()}")
time.sleep(max(0, int(3 * 60 - (time.time() - t0))))