From 7fdc771d528b8ada54584e2912a4d7a52e4184ed Mon Sep 17 00:00:00 2001 From: Stefano Assenzo Date: Fri, 24 Mar 2023 16:00:55 +0000 Subject: [PATCH] Bugs fixed in school schedule generation, add new option on Discord bot --- src/bot/discord/discord_bot.py | 24 +++++++- src/bot/telegram/main.py | 12 ++-- src/events/school_time/update_time_school.py | 59 ++++++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/src/bot/discord/discord_bot.py b/src/bot/discord/discord_bot.py index 4abde02..080a927 100644 --- a/src/bot/discord/discord_bot.py +++ b/src/bot/discord/discord_bot.py @@ -90,10 +90,18 @@ async def change_school_time( "Select hour school", choices=["First hour", "Second hour", "Third hour", "Fourth hour", "Fifth hour", "Sixth hour", "Seventh hour", "Eighth hour", "Ninth hour"], required=True, - ), text: str + ), text: str, + teacher: Option(str, + "Write teacher", + required=False, + ), + room: Option(str, + "Write room school", + required=False, + ), ): - await ctx.respond(f"Day selected: {day}, Hour school selected: {hour_school}, Text: {text}") + await ctx.respond(f"Day selected: {day}, Hour school selected: {hour_school}, Text: {text}, Teacher: {teacher} ,Room: {room}") # Update the subject on MongoDB if hour_school == "First hour": hour_school = "0" @@ -121,6 +129,18 @@ async def change_school_time( {"$set": {f"School Subject.{day}.{int(hour_school)}.Subject": text}} ) + if teacher != None: + collection.update_one( + {"_id": ObjectId(array_document)}, + {"$set": {f"School Subject.{day}.{int(hour_school)}.Teacher": teacher}} + ) + + if room != None: + collection.update_one( + {"_id": ObjectId(array_document)}, + {"$set": {f"School Subject.{day}.{int(hour_school)}.Room": room}} + ) + @bot.slash_command(name='confirm', description='Confirm change school time') async def confirm(ctx : ApplicationContext): await ctx.respond(f"Confirm") diff --git a/src/bot/telegram/main.py b/src/bot/telegram/main.py index 87bb83e..efe7253 100644 --- a/src/bot/telegram/main.py +++ b/src/bot/telegram/main.py @@ -3,6 +3,7 @@ from dotenv import load_dotenv from telebot import telebot import time import datetime +import threading import time import schedule import pymongo @@ -75,9 +76,12 @@ def send_notification(): for i in find_document: for b in array_username: 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": + elif now.strftime("%H:%M") == "20:00": if tomorrow == "Sunday" or tomorrow == "Saturday": - print("Nope") + if tomorrow == "Monday": + 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: for i in find_document: for b in array_username: @@ -89,9 +93,9 @@ schedule.every().day.at("08:50").do(send_notification) schedule.every().day.at("10:05").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("21:00").do(send_notification) +schedule.every().day.at("20:00").do(send_notification) now = datetime.datetime.now() -#t1 = threading.Thread(target=bot.polling).start() +t1 = threading.Thread(target=bot.polling).start() while True: time.sleep(10) diff --git a/src/events/school_time/update_time_school.py b/src/events/school_time/update_time_school.py index edb30ba..936d71a 100644 --- a/src/events/school_time/update_time_school.py +++ b/src/events/school_time/update_time_school.py @@ -827,4 +827,63 @@ def update_time_school(): else: pass + #for i in range(1,5): + # # Search on Mongodb every first hour of the day if is egual to CALF1 LINGUA ITALIANA + # print(i) + # find_document_school_time_table = list(collection.find({}, {"Date": long_date})) + # array_document_school_time_table = find_document_school_time_table[0]["_id"] + # print([array_test[0]]) + # # Print Subject 0 Monday + # print(array_document_school_time_table[0]["School Subject"][array_test[0]][0]["Subject"]) + + for i in range(0 , 5): + for x in collection.find({},{ "Date": long_date, "School Subject": 1, "_id": 0}): + testgaga = x['School Subject'][array_test[0]][0]['Subject'] + print(testgaga) + if testgaga == "0" or testgaga == 0 or testgaga == None: + collection.update_one( + { "_id": ObjectId(array_document_school_time_table)}, + { "$set": { + "School Subject." + array_test[0] + "." + str(i)+ ".Subject": "", + } + } + ) + collection.update_one( + { "_id": ObjectId(array_document_school_time_table)}, + { "$set": { + "School Subject." + array_test[0] + "." + str(i)+ ".Teacher": "", + } + } + ) + collection.update_one( + { "_id": ObjectId(array_document_school_time_table)}, + { "$set": { + "School Subject." + array_test[0] + "." + str(i)+ ".Room": "", + } + } + ) + else: + try: + remove_things_in_front = testgaga.split(' ', 1)[1] + if remove_things_in_front == "ITALIANA" or remove_things_in_front == "ELETTRICO": + if remove_things_in_front == "ELETTRICO": + remove_things_in_front = "LAB. ELETTRICO" + collection.update_one( + { "_id": ObjectId(array_document_school_time_table)}, + { "$set": { + "School Subject." + array_test[0] + "." + str(i)+ ".Subject": remove_things_in_front, + } + } + ) + pass + else: + collection.update_one( + { "_id": ObjectId(array_document_school_time_table)}, + { "$set": { + "School Subject." + array_test[0] + "." + str(i)+ ".Subject": remove_things_in_front, + } + } + ) + except: + pass update_time_school() \ No newline at end of file