Fix little things

This commit is contained in:
Stefano Assenzo 2023-03-31 16:20:24 +00:00 committed by GitHub
parent 62b9c93a2c
commit 9bbe459585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 64 deletions

7
app.py
View File

@ -1,6 +1,9 @@
#import src.bot.discord.discord_bot
from flask import Flask, render_template, url_for, request, redirect, session
from pymongo import MongoClient
from dotenv import load_dotenv
import threading
import logging
import urllib
import bcrypt
@ -136,6 +139,10 @@ def logout():
else:
return render_template('index.html')
# Threading discord_bot.py
#import src.events.school_time.email_read # Start email_read.py
#x = threading.Thread(target=os.system('python src/bot/discord/discord_bot.py')).start()
if __name__ == '__main__':
logging.info("Web server started!")
app.run(port=4999, debug=True)

View File

@ -1,4 +1,4 @@
from commands.moderation import ban, kick, clear_msg
#from commands.moderation import ban, kick, clear_msg
from discord.commands.context import ApplicationContext # Discord
from selenium.webdriver.firefox.options import Options # Selenium
from discord.commands import Option # Discord
@ -56,7 +56,7 @@ async def orario():
for document in documents:
for day in document['School Subject']:
for i, subject in enumerate(document['School Subject'][day]):
if subject['Subject'] == "LINGUA ITALIANA":
if subject['Subject'] == "LINGUA ITALIANA" or "ITALIANA":
# Send a message on channel #general with the subject found and the index of the subject
options = Options() # Set options
options.add_argument("--headless") # Headless mode (so you don't see the browser)

View File

@ -8,6 +8,7 @@ import time
import schedule
import pymongo
import urllib
import pytz
import os
load_dotenv()
@ -87,16 +88,18 @@ def send_notification():
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'])
schedule.every().day.at("05:50").do(send_notification)
schedule.every().day.at("06:50").do(send_notification)
schedule.every().day.at("07:50").do(send_notification)
schedule.every().day.at("08:50").do(send_notification)
schedule.every().day.at("9: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("12:05").do(send_notification)
schedule.every().day.at("20:00").do(send_notification)
now = datetime.datetime.now()
tz = pytz.timezone("Europe/Rome")
now = datetime.datetime.now(tz)
t1 = threading.Thread(target=bot.polling).start()
while True:
time.sleep(10)
print(now)
schedule.run_pending()

View File

@ -10,3 +10,4 @@ telebot==0.0.5
schedule==1.1.0
pymongo==4.3.3
urllib3==1.26.13
pytz==2022.6

View File

@ -826,64 +826,44 @@ def update_time_school():
)
else:
pass
#
docs = collection.find()
#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"])
# Iterate over each document
for doc in docs:
# Access the ObjectId field of the document
doc_id = doc["_id"]
day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
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:
pomate = doc["School Subject"][day[i]][0]['Subject']
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"
remove_things_in_front = pomate.split(' ', 1)[1]
if remove_things_in_front == "ITALIANA":
collection.update_one(
{ "_id": ObjectId(array_document_school_time_table)},
{ "_id": ObjectId(doc_id)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(i)+ ".Subject": remove_things_in_front,
"School Subject." + day[i] + ".0.Subject": "LINGUA ITALIANA",
}
}
)
elif remove_things_in_front == "ELETTRICO":
collection.update_one(
{ "_id": ObjectId(doc_id)},
{ "$set": {
"School Subject." + day[i] + ".0.Subject": "LAB. ELETTRICO",
}
}
)
pass
else:
collection.update_one(
{ "_id": ObjectId(array_document_school_time_table)},
{ "_id": ObjectId(doc_id)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(i)+ ".Subject": remove_things_in_front,
"School Subject." + day[i] + ".0.Subject": remove_things_in_front,
}
}
)
except:
pass
update_time_school()