diff --git a/.gitignore b/.gitignore index cd6bb21..293664a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ __pycache__ test.py school_time.xlsx venv -screenshot.png \ No newline at end of file +screenshot.png +Dockerfile \ No newline at end of file diff --git a/src/bot/telegram/bot.py b/src/bot/telegram/bot.py index b3f9e81..ae08b1e 100644 --- a/src/bot/telegram/bot.py +++ b/src/bot/telegram/bot.py @@ -38,10 +38,6 @@ def subscribe(message): ) bot.send_message(message.chat.id, "You are subscribed") -def recheck(): - time.sleep(60) - send_notification() - def send_notification(): today = datetime.datetime.today().strftime('%A') tomorrow = (datetime.datetime.today() + datetime.timedelta(days=1)).strftime('%A') @@ -58,33 +54,27 @@ def send_notification(): if now.strftime("%H:%M") == "07:50": for i in find_document: for b in array_username: - bot.send_message(b, str(i['School Subject']['Monday'][0]['Room']) + ", " + i['School Subject']['Monday'][0]['Teacher'] + ", " + i['School Subject']['Monday'][0]['Subject'] + "\n" + "Successiva: " + str(i['School Subject']['Monday'][1]['Room']) + ", " + i['School Subject']['Monday'][1]['Teacher'] + ", " + i['School Subject']['Monday'][1]['Subject']) - recheck() - elif now.strftime("%H:%M") == "8:50": + bot.send_message(b, str(i['School Subject'][today][0]['Room']) + ", " + i['School Subject'][today][0]['Teacher'] + ", " + i['School Subject'][today][0]['Subject'] + "\n" + "Successiva: " + str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + i['School Subject'][today][1]['Subject']) + elif now.strftime("%H:%M") == "08:50": for i in find_document: for b in array_username: - bot.send_message(b, str(i['School Subject']['Monday'][1]['Room']) + ", " + i['School Subject']['Monday'][1]['Teacher'] + ", " + str(i['School Subject']['Monday'][1]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][2]['Room']) + ", " + i['School Subject']['Monday'][2]['Teacher'] + ", " + i['School Subject']['Monday'][2]['Subject']) - recheck() + bot.send_message(b, str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + str(i['School Subject'][today][1]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + i['School Subject'][today][2]['Subject']) elif now.strftime("%H:%M") == "9:50": for i in find_document: for b in array_username: - bot.send_message(b, str(i['School Subject']['Monday'][2]['Room']) + ", " + i['School Subject']['Monday'][2]['Teacher'] + ", " + str(i['School Subject']['Monday'][2]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][3]['Room']) + ", " + i['School Subject']['Monday'][3]['Teacher'] + ", " + i['School Subject']['Monday'][3]['Subject']) - recheck() + bot.send_message(b, str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + str(i['School Subject'][today][2]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][3]['Room']) + ", " + i['School Subject'][today][3]['Teacher'] + ", " + i['School Subject'][today][3]['Subject']) elif now.strftime("%H:%M") == "11:05": for i in find_document: for b in array_username: - bot.send_message(b, str(i['School Subject']['Monday'][3]['Room']) + ", " + i['School Subject']['Monday'][3]['Teacher'] + ", " + str(i['School Subject']['Monday'][3]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][4]['Room']) + ", " + i['School Subject']['Monday'][4]['Teacher'] + ", " + i['School Subject']['Monday'][4]['Subject']) - recheck() + bot.send_message(b, str(i['School Subject'][today][3]['Room']) + ", " + i['School Subject'][today][3]['Teacher'] + ", " + str(i['School Subject'][today][3]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][4]['Room']) + ", " + i['School Subject'][today][4]['Teacher'] + ", " + i['School Subject'][today][4]['Subject']) elif now.strftime("%H:%M") == "12:05": for i in find_document: for b in array_username: - bot.send_message(b, str(i['School Subject']['Monday'][4]['Room']) + ", " + i['School Subject']['Monday'][4]['Teacher'] + ", " + str(i['School Subject']['Monday'][4]['Subject']) + "\n" + "Successiva: " + str(i['School Subject']['Monday'][5]['Room']) + ", " + i['School Subject']['Monday'][5]['Teacher'] + ", " + i['School Subject']['Monday'][5]['Subject']) - recheck() + bot.send_message(b, str(i['School Subject'][today][4]['Room']) + ", " + i['School Subject'][today][4]['Teacher'] + ", " + str(i['School Subject'][today][4]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][5]['Room']) + ", " + i['School Subject'][today][5]['Teacher'] + ", " + i['School Subject'][today][5]['Subject']) elif now.strftime("%H:%M") == "13:05": for i in find_document: for b in array_username: - bot.send_message(b, str(i['School Subject']['Monday'][5]['Room']) + ", " + i['School Subject']['Monday'][5]['Teacher'] + ", " + str(i['School Subject']['Monday'][5]['Subject'])) - recheck() + bot.send_message(b, str(i['School Subject'][today][5]['Room']) + ", " + i['School Subject'][today][5]['Teacher'] + ", " + str(i['School Subject'][today][5]['Subject'])) elif now.strftime("%H:%M") == "21:00": if tomorrow == "Sunday" or tomorrow == "Saturday": print("Nope") @@ -92,10 +82,14 @@ def send_notification(): for i in find_document: for b in array_username: bot.send_message(b, i['School Subject'][tomorrow][0]['Subject'] + ", " + i['School Subject'][tomorrow][0]['Teacher'] + "\n" + i['School Subject'][tomorrow][1]['Subject'] + ", " + i['School Subject'][tomorrow][1]['Teacher'] + "\n" + i['School Subject'][tomorrow][2]['Subject'] + ", " + i['School Subject'][tomorrow][2]['Teacher'] + "\n" + i['School Subject'][tomorrow][3]['Subject'] + ", " + i['School Subject'][tomorrow][3]['Teacher'] + "\n" + i['School Subject'][tomorrow][4]['Subject'] + ", " + i['School Subject'][tomorrow][4]['Teacher'] + "\n" + i['School Subject'][tomorrow][5]['Subject'] + ", " + i['School Subject'][tomorrow][5]['Teacher']) - else: - recheck() schedule.every().day.at("07:50").do(send_notification) +schedule.every().day.at("08:50").do(send_notification) +schedule.every().day.at("09:50").do(send_notification) +schedule.every().day.at("11:05").do(send_notification) +schedule.every().day.at("12:05").do(send_notification) +schedule.every().day.at("13:05").do(send_notification) +schedule.every().day.at("21:00").do(send_notification) now = datetime.datetime.now() t1 = threading.Thread(target=bot.polling).start() diff --git a/src/bot/telegram/requirements.txt b/src/bot/telegram/requirements.txt new file mode 100644 index 0000000..ca25296 --- /dev/null +++ b/src/bot/telegram/requirements.txt @@ -0,0 +1,6 @@ +pymongo==4.3.3 +urllib3==1.26.13 +python-dotenv==0.21.0 +schedule==1.1.0 +telebot==0.0.5 +pybson==0.5.9 \ No newline at end of file