Compare commits

..

2 Commits

Author SHA1 Message Date
Stefano Assenzo 34d18eb4ed
Fix little bug on Discord bot 2023-03-24 16:38:22 +00:00
Stefano Assenzo 7fdc771d52
Bugs fixed in school schedule generation, add new option on Discord bot 2023-03-24 16:00:55 +00:00
3 changed files with 108 additions and 10 deletions

View File

@ -55,7 +55,7 @@ async def orario():
for document in documents: for document in documents:
for day in document['School Subject']: for day in document['School Subject']:
for i, subject in enumerate(document['School Subject'][day]): for i, subject in enumerate(document['School Subject'][day]):
if subject['Subject'] == "CALF1 LINGUA ITALIANA": if subject['Subject'] == "LINGUA ITALIANA":
# Send a message on channel #general with the subject found and the index of the subject # Send a message on channel #general with the subject found and the index of the subject
options = Options() # Set options options = Options() # Set options
options.add_argument("--headless") # Headless mode (so you don't see the browser) options.add_argument("--headless") # Headless mode (so you don't see the browser)
@ -67,14 +67,29 @@ async def orario():
driver.get_screenshot_as_file("screenshot.png") driver.get_screenshot_as_file("screenshot.png")
driver.quit() driver.quit()
channel = bot.get_channel(GENERAL_ID) channel = bot.get_channel(int(GENERAL_ID))
await channel.send(file=discord.File("screenshot.png")) await channel.send(file=discord.File("screenshot.png"))
os.remove("screenshot.png") os.remove("screenshot.png")
send_screenshot += 1 send_screenshot += 1
else: else:
pass pass
channel = bot.get_channel(GENERAL_ID) if i == 0:
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']} at index: {i}") i = "First hour"
elif i == 1:
i = "Second hour"
elif i == 2:
i = "Third hour"
elif i == 3:
i = "Fourth hour"
elif i == 4:
i = "Fifth hour"
elif i == 5:
i = "Sixth hour"
elif i == 6:
i = "Seventh hour"
elif i == 7:
i = "Eighth hour"
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']}")
send_screenshot = 0 send_screenshot = 0
@ -90,10 +105,18 @@ async def change_school_time(
"Select hour school", "Select hour school",
choices=["First hour", "Second hour", "Third hour", "Fourth hour", "Fifth hour", "Sixth hour", "Seventh hour", "Eighth hour", "Ninth hour"], choices=["First hour", "Second hour", "Third hour", "Fourth hour", "Fifth hour", "Sixth hour", "Seventh hour", "Eighth hour", "Ninth hour"],
required=True, 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 # Update the subject on MongoDB
if hour_school == "First hour": if hour_school == "First hour":
hour_school = "0" hour_school = "0"
@ -121,6 +144,18 @@ async def change_school_time(
{"$set": {f"School Subject.{day}.{int(hour_school)}.Subject": text}} {"$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') @bot.slash_command(name='confirm', description='Confirm change school time')
async def confirm(ctx : ApplicationContext): async def confirm(ctx : ApplicationContext):
await ctx.respond(f"Confirm") await ctx.respond(f"Confirm")

View File

@ -3,6 +3,7 @@ from dotenv import load_dotenv
from telebot import telebot from telebot import telebot
import time import time
import datetime import datetime
import threading
import time import time
import schedule import schedule
import pymongo import pymongo
@ -75,9 +76,12 @@ def send_notification():
for i in find_document: for i in find_document:
for b in array_username: 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'])) 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": 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: else:
for i in find_document: for i in find_document:
for b in array_username: 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("10:05").do(send_notification)
schedule.every().day.at("11: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("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() now = datetime.datetime.now()
#t1 = threading.Thread(target=bot.polling).start() t1 = threading.Thread(target=bot.polling).start()
while True: while True:
time.sleep(10) time.sleep(10)

View File

@ -827,4 +827,63 @@ def update_time_school():
else: else:
pass 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() update_time_school()