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 flask import Flask, render_template, url_for, request, redirect, session
from pymongo import MongoClient from pymongo import MongoClient
from dotenv import load_dotenv from dotenv import load_dotenv
import threading
import logging import logging
import urllib import urllib
import bcrypt import bcrypt
@ -136,6 +139,10 @@ def logout():
else: else:
return render_template('index.html') 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__': if __name__ == '__main__':
logging.info("Web server started!") logging.info("Web server started!")
app.run(port=4999, debug=True) 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 discord.commands.context import ApplicationContext # Discord
from selenium.webdriver.firefox.options import Options # Selenium from selenium.webdriver.firefox.options import Options # Selenium
from discord.commands import Option # Discord from discord.commands import Option # Discord
@ -56,7 +56,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'] == "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 # 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)

View File

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

View File

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

View File

@ -826,64 +826,44 @@ def update_time_school():
) )
else: else:
pass pass
#
docs = collection.find()
#for i in range(1,5): # Iterate over each document
# # Search on Mongodb every first hour of the day if is egual to CALF1 LINGUA ITALIANA for doc in docs:
# print(i) # Access the ObjectId field of the document
# find_document_school_time_table = list(collection.find({}, {"Date": long_date})) doc_id = doc["_id"]
# array_document_school_time_table = find_document_school_time_table[0]["_id"] day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
# print([array_test[0]]) for i in range(0, 5):
# # Print Subject 0 Monday pomate = doc["School Subject"][day[i]][0]['Subject']
# print(array_document_school_time_table[0]["School Subject"][array_test[0]][0]["Subject"]) try:
remove_things_in_front = pomate.split(' ', 1)[1]
for i in range(0 , 5): if remove_things_in_front == "ITALIANA":
for x in collection.find({},{ "Date": long_date, "School Subject": 1, "_id": 0}): collection.update_one(
testgaga = x['School Subject'][array_test[0]][0]['Subject'] { "_id": ObjectId(doc_id)},
print(testgaga) { "$set": {
if testgaga == "0" or testgaga == 0 or testgaga == None: "School Subject." + day[i] + ".0.Subject": "LINGUA ITALIANA",
collection.update_one( }
{ "_id": ObjectId(array_document_school_time_table)}, }
{ "$set": { )
"School Subject." + array_test[0] + "." + str(i)+ ".Subject": "", elif remove_things_in_front == "ELETTRICO":
} collection.update_one(
} { "_id": ObjectId(doc_id)},
) { "$set": {
collection.update_one( "School Subject." + day[i] + ".0.Subject": "LAB. ELETTRICO",
{ "_id": ObjectId(array_document_school_time_table)}, }
{ "$set": { }
"School Subject." + array_test[0] + "." + str(i)+ ".Teacher": "", )
} else:
} collection.update_one(
) { "_id": ObjectId(doc_id)},
collection.update_one( { "$set": {
{ "_id": ObjectId(array_document_school_time_table)}, "School Subject." + day[i] + ".0.Subject": remove_things_in_front,
{ "$set": { }
"School Subject." + array_test[0] + "." + str(i)+ ".Room": "", }
} )
} except:
) pass
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()