-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
56 lines (44 loc) · 1.21 KB
/
main.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import logging
import time
import schedule
from threading import Thread
from bot_config import updater
import bot_handlers # noqa (ignore linter warning)
from bot_routines import (
parse_alerts_routine,
delete_past_alerts_routine,
notify_chats_routine,
)
ROUTINES_INTERVAL = 15
# Enable logging
logging.basicConfig(
format="%(asctime)s %(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
filename="bot.log",
level=logging.DEBUG,
)
# Initialize bot routines
try:
schedule.every(ROUTINES_INTERVAL).minutes.do(delete_past_alerts_routine)
schedule.every(ROUTINES_INTERVAL).minutes.do(parse_alerts_routine)
schedule.every(ROUTINES_INTERVAL).minutes.do(notify_chats_routine)
except Exception as error:
logging.exception(f"Error in main routine: {error}")
pass
# Thread for running routines periodically
class RoutinesThread(Thread):
def run(self):
while True:
schedule.run_pending()
time.sleep(60)
def main():
updater.start_polling()
# Start routines thread
fRoutines = RoutinesThread()
fRoutines.daemon = True
fRoutines.start()
# Run the bot until Ctrl-C is pressed
updater.idle()
if __name__ == "__main__":
main()