Bugs fixed in school schedule generation, add new option on Discord bot

This commit is contained in:
Stefano Assenzo 2023-03-24 16:00:55 +00:00 committed by GitHub
parent efa9348cfd
commit 7fdc771d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 6 deletions

View File

@ -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")

View File

@ -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)

View File

@ -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()