Compare commits

..

31 Commits

Author SHA1 Message Date
583487d204 Fix bug Bot Telegram 2023-09-29 16:34:24 +02:00
Stefano Assenzo
9bbe459585 Fix little things 2023-03-31 16:20:24 +00:00
Stefano Assenzo
62b9c93a2c Fix bot Discord and add new command for send image school time table - Finish upload homework on MongoDB (there is a small bug but it is not a big deal) 2023-03-25 16:43:20 +00:00
Stefano Assenzo
815f3fc0d6 Optimization of code for tasks.
TO-DO Send all data to MongoDB
2023-03-25 11:19:10 +00:00
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
Stefano Assenzo
efa9348cfd Merge branch 'dev' of https://github.com/assenzostefano/class-website into dev 2023-03-11 18:04:40 +00:00
Stefano Assenzo
660dfa283a So now? 2023-03-11 18:04:16 +00:00
Stefano Assenzo
fb2df8c658 Update main.py 2023-03-11 19:03:41 +01:00
Stefano Assenzo
792be8591b Update main.py 2023-03-11 18:33:05 +01:00
Stefano Assenzo
f336cffa60 Update main.py 2023-03-11 10:19:13 +01:00
Stefano Assenzo
2b7665f8ad Update main.py 2023-03-10 20:06:03 +01:00
Stefano Assenzo
4e0e1c545f Update main.py 2023-03-10 20:04:54 +01:00
Stefano Assenzo
9894a6957c Update main.py 2023-03-07 15:45:34 +01:00
Stefano Assenzo
f7f9181c6c Update main.py 2023-03-07 15:45:15 +01:00
Stefano Assenzo
0e77be9e07 Update main.py 2023-03-07 15:41:00 +01:00
Stefano Assenzo
c9e971c6bf Update main.py 2023-03-07 10:57:12 +01:00
Stefano Assenzo
03dc72fdc6 Update main.py 2023-03-07 07:57:25 +01:00
Stefano Assenzo
d8db86a33d ehi 2023-03-06 16:07:05 +00:00
Stefano Assenzo
f19d664646 So now? 2023-03-06 16:06:59 +00:00
Stefano Assenzo
2c78f7ed1e Everything should be right now 2023-03-06 16:02:21 +00:00
Stefano Assenzo
d6668d255d Update main.py 2023-03-06 16:34:00 +01:00
Stefano Assenzo
88097ac588 Update main.py 2023-03-06 16:18:56 +01:00
Stefano Assenzo
ae231d7952 Update main.py 2023-03-06 16:15:11 +01:00
Stefano Assenzo
a46fa83505 Create requirements.txt 2023-03-05 19:37:58 +01:00
Stefano Assenzo
2feba359e2 Rename bot.py to main.py 2023-03-05 19:34:00 +01:00
Stefano Assenzo
ef2d9a520b I'm finally done with this Telegram bot 2023-03-04 16:08:33 +00:00
Stefano Assenzo
5f2594ed4a Fix all 2023-03-03 16:02:42 +00:00
Stefano Assenzo
566d3e2811 I am doing too many things 2023-03-03 15:14:12 +00:00
Stefano Assenzo
4f4458c425 I forgot to remove the print 2023-02-17 17:04:36 +00:00
Stefano Assenzo
44ce965fb3 Fix bug 2023-02-17 17:02:56 +00:00
13 changed files with 511 additions and 1665 deletions

3
.gitignore vendored
View File

@@ -6,4 +6,5 @@ __pycache__
test.py
school_time.xlsx
venv
screenshot.png
screenshot.png
Dockerfile

19
app.py
View File

@@ -1,12 +1,12 @@
from urllib.request import Request, urlopen
from flask import Flask, render_template, url_for, request, redirect, session, flash, jsonify
from flask_pymongo import PyMongo
from dotenv import load_dotenv
import bcrypt
import urllib
#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 json
import urllib
import bcrypt
import sys
import os
@@ -55,7 +55,6 @@ def MongoDB():
records = MongoDB()
#assign URLs to have a particular route
@app.route("/register", methods=['post', 'get'])
def register():
@@ -140,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
@@ -44,18 +44,19 @@ bot = discord.Bot()
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
bot.loop.create_task(orario())
orario.start()
# Search on MongoDB the subject and send a message on Discord if the subject is found
@tasks.loop(seconds=1)
@tasks.loop(seconds=10)
async def orario():
documents = collection.find()
send_screenshot = 0
print("Searching for subject...")
# Iterate through the documents
for document in documents:
for day in document['School Subject']:
for i, subject in enumerate(document['School Subject'][day]):
if subject['Subject'] == "CALF1 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)
@@ -64,17 +65,31 @@ async def orario():
driver = webdriver.Firefox(options=options)
driver.get('http://127.0.0.1:4999/orario')
time.sleep(5)
driver.get_screenshot_as_file("screenshot.png")
driver.quit()
channel = bot.get_channel(GENERAL_ID)
channel = bot.get_channel(int(GENERAL_ID))
await channel.send(file=discord.File("screenshot.png"))
os.remove("screenshot.png")
send_screenshot += 1
else:
pass
channel = bot.get_channel(GENERAL_ID)
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']} at index: {i}")
if i == 0:
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
@@ -90,10 +105,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,10 +144,32 @@ 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")
collection_email.update_one({}, {"$set": {"Send on Whatsapp": "yes"}})
options = Options() # Set options
options.add_argument("--headless") # Headless mode (so you don't see the browser)
options.add_argument('--disable-gpu') # Disable GPU
driver = webdriver.Firefox(options=options)
driver.get('http://127.0.0.1:4999/orario')
driver.get_screenshot_as_file("screenshot.png")
driver.quit()
channel = bot.get_channel(int(GENERAL_ID))
await channel.send(file=discord.File("screenshot.png"))
os.remove("screenshot.png")
#@bot.slash_command()
#@discord.default_permissions(ban_members = True, administrator = True)
#async def ban(ctx, member: Option(discord.Member, description="Select a member", required=True), reason: Option(str, description="Reason", required=True)):
@@ -141,4 +186,6 @@ async def confirm(ctx : ApplicationContext):
#async def clear(ctx, messages: Option(int, description="Amount of messages to delete", required=True)):
# clear_msg.clear_messages(ctx, amount = messages)
bot.run(DISCORD_TOKEN)
while True:
bot.run(DISCORD_TOKEN)
orario.start()

108
src/bot/telegram/main.py Normal file
View File

@@ -0,0 +1,108 @@
from bson.objectid import ObjectId
from dotenv import load_dotenv
from telebot import telebot
import time
import datetime
import threading
import time
import schedule
import pymongo
import urllib
import pytz
import os
load_dotenv()
PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
URL_MONGODB = os.getenv('URL_MONGODB') #URL for MongoDB
mongo_url = "mongodb+srv://elci:" + urllib.parse.quote_plus(PASSWORD_MONGODB) + URL_MONGODB #URL for MongoDB (with password)
client = pymongo.MongoClient(mongo_url) #Connect to MongoDB
database = client["website-class"] #Database name
collection = database["subscribe"] #Collection school time table current
collection_schooltime = database["school-time-table"] #Collection school time table current
API_TOKEN = os.getenv('TELEGRAM_TOKEN')
bot = telebot.TeleBot(API_TOKEN)
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.send_message(message.chat.id, "Hello, I'm a bot")
@bot.message_handler(commands=['subscribe'])
def subscribe(message):
take_id = message.from_user.id #Get user id
#Insert the id of the user who writes /subscribe in the database
find_document_username = list(collection.find({}, {"_id": 1}))
array_username = find_document_username[0]["_id"]
collection.update_one(
{ "_id": ObjectId(array_username)},
{
"$push": { "username": take_id }
}
)
bot.send_message(message.chat.id, "You are subscribed")
def send_notification():
today = datetime.datetime.today().strftime('%A')
tomorrow = (datetime.datetime.today() + datetime.timedelta(days=1)).strftime('%A')
now = datetime.datetime.now()
if today == "Saturday" or today == "Sunday":
print("Today is weekend")
else:
# Alla prima ora (7.50) manda una notifica a tutti gli utenti che hanno scritto /subscribe della materia della prima ora
find_document = list(collection_schooltime.find({}, {"_id": 0, "School Subject": 1}))
collection_find_username = list(collection.find({}, {"username": 1,})) #Find all username in collection
array_username = collection_find_username[0]["username"] #Array with all username
#gaga = find_document['School Subject'][today][0]['Subject']
print(now.strftime("%H:%M"))
if now.strftime("%H:%M") == "07:50":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][0]['Room']) + ", " + i['School Subject'][today][0]['Teacher'] + ", " + i['School Subject'][today][0]['Subject'] + "\n" + "Successiva: " + str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + i['School Subject'][today][1]['Subject'])
elif now.strftime("%H:%M") == "08:50":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + str(i['School Subject'][today][1]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + i['School Subject'][today][2]['Subject'])
elif now.strftime("%H:%M") == "09:50":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + str(i['School Subject'][today][2]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][3]['Room']) + ", " + i['School Subject'][today][3]['Teacher'] + ", " + i['School Subject'][today][3]['Subject'])
elif now.strftime("%H:%M") == "11:05":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][3]['Room']) + ", " + i['School Subject'][today][3]['Teacher'] + ", " + str(i['School Subject'][today][3]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][4]['Room']) + ", " + i['School Subject'][today][4]['Teacher'] + ", " + i['School Subject'][today][4]['Subject'])
elif now.strftime("%H:%M") == "12:05":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][4]['Room']) + ", " + i['School Subject'][today][4]['Teacher'] + ", " + str(i['School Subject'][today][4]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][5]['Room']) + ", " + i['School Subject'][today][5]['Teacher'] + ", " + i['School Subject'][today][5]['Subject'])
elif now.strftime("%H:%M") == "13:05":
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":
if tomorrow == "Sunday" or tomorrow == "Saturday":
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:
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'])
def test_time():
print("Test")
schedule.every().day.at("07:50").do(send_notification)
schedule.every().day.at("08:50").do(send_notification)
schedule.every().day.at("09:50").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("13:05").do(send_notification)
schedule.every().day.at("21:05").do(send_notification)
tz = pytz.timezone("Europe/Rome")
now = datetime.datetime.now()
t1 = threading.Thread(target=bot.polling).start()
while True:
time.sleep(10)
print(now)
schedule.run_pending()

View File

@@ -0,0 +1,13 @@
pymongo==4.3.3
urllib3==1.26.13
python-dotenv==0.21.0
schedule==1.1.0
telebot==0.0.5
pybson==0.5.9
pybson==0.5.9
python-dotenv==0.21.0
telebot==0.0.5
schedule==1.1.0
pymongo==4.3.3
urllib3==1.26.13
pytz==2022.6

View File

@@ -1,60 +1,219 @@
# Import file for check homework
from day_one import day_one
# Libraries for open and use Firefox
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import pymongo
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium import webdriver
# Libraries for MongoDB and .env file
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import datetime
from dotenv import load_dotenv
import urllib.parse
import pymongo
import time
import os
import urllib.parse
import time
# Disable GPU for Firefox
options = Options()
options.add_argument('--disable-gpu')
# Disable showing Firefox window
options.headless = True
#Load .env file
load_dotenv() #Load .env file
USERNAME = os.getenv('USERNAME_NUVOLA') #Username for Nuvola
PASSWORD = os.getenv('PASSWORD_NUVOLA') #Password for Nuvola
PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
URL_MONGODB = os.getenv('URL_MONGODB') #URL for MongoDB
# Initialize the browser with the given options
browser = webdriver.Firefox(options=options)
# Wait for up to 10 seconds for elements to appear
wait = WebDriverWait(browser, 10)
# Connect to the MongoDB database
mongo_url = "mongodb+srv://elci:" + urllib.parse.quote_plus(PASSWORD_MONGODB) + URL_MONGODB #URL for MongoDB (with password)
client = pymongo.MongoClient(mongo_url) #Connect to MongoDB
database = client["website-class"] #Database name
collection = database["homework"] #Collection school time table current
db = client["website-class"]
# Options for Firefox
options = Options() # Set options
options.add_argument("--headless") # Headless mode (so you don't see the browser)
options.add_argument('--disable-gpu') # Disable GPU
# Get today's date as a string in the format "YYYY-MM-DD"
today = datetime.datetime.now().strftime("%Y-%m-%d")
def start_search():
time.sleep(7200)
global driver
driver = webdriver.Firefox(options=options) # Open Firefox and set options
driver.get("https://nuvola.madisoft.it/login") # Open Nuvola website
username = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.ID, "username"))) # Wait for the username input
password = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.ID, "password"))) # Wait for the password input
# Get the collection for today's data
collection = db["homework"]
username.click()
username.clear()
username.send_keys(USERNAME) # Insert username
password.click()
password.clear()
password.send_keys(PASSWORD) # Insert password
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div[2]/div/div[2]/form/button"))).click() # Click on login button
# Initialize the URL for Cloud
url = 'https://nuvola.madisoft.it/login'
# Section Homework
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/div[1]/nav/div/div/a[6]"))).click() # Click on homework button
homework_check()
browser.get(url)
username = WebDriverWait(browser, 100).until(EC.element_to_be_clickable((By.ID, "username"))) # Wait for the username input
password = WebDriverWait(browser, 100).until(EC.element_to_be_clickable((By.ID, "password"))) # Wait for the password input
username.click()
username.clear()
username.send_keys(USERNAME) # Insert username
password.click()
password.clear()
password.send_keys(PASSWORD) # Insert password
WebDriverWait(browser, 50).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div[2]/div/div[2]/form/button"))).click() # Click on login button
# Section Homework
WebDriverWait(browser, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/div[1]/nav/div/div/a[6]"))).click() # Click on homework button
def homework_check():
day_one.giorno_uno(driver, collection)
driver.close()
start_search()
print("Finish")
# Click on the "Next Day" button to go to the next day's tasks
next_day_button = WebDriverWait(browser, 250).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]')))
start_search()
def wait_homework():
browser.quit()
time.sleep(10800)
check_homework()
def check_homework():
for i in range(0, 10):
try:
print(i)
date = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))).text)
subject = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/h2"))).text)
teacher = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/span"))).text)
text1 = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text)
print(date)
print(subject)
print(text1)
# Search on MongoDB if the date is already present on the database
if collection.find_one({"Date": date}) is None:
collection.insert_one({"Date": date, "Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}
)
else:
collection.update_one(
{"Date": date},
{"$addToSet": {"Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}}
)
subject = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text)
teacher = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/span"))).text)
text1 = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text)
print(subject)
print(teacher)
print(text1)
if collection.find_one({"Date": date}) is None:
collection.insert_one({"Date": date, "Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}
)
else:
collection.update_one(
{"Date": date},
{"$addToSet": {"Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}}
)
try:
subject = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text)
teacher = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/span"))).text)
text1 = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text)
print(subject)
print(teacher)
print(text1)
if collection.find_one({"Date": date}) is None:
collection.insert_one({"Date": date, "Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}
)
else:
collection.update_one(
{"Date": date},
{"$addToSet": {"Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}}
)
except:
subject = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text)
teacher = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/span"))).text)
text1 = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text)
print(subject)
print(teacher)
print(text1)
if collection.find_one({"Date": date}) is None:
collection.insert_one({"Date": date, "Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}
)
else:
collection.update_one(
{"Date": date},
{"$addToSet": {"Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}}
)
try:
subject = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text)
teacher = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/span"))).text)
text1 = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text)
print(subject)
print(teacher)
print(text1)
if collection.find_one({"Date": date}) is None:
collection.insert_one({"Date": date, "Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}
)
else:
collection.update_one(
{"Date": date},
{"$addToSet": {"Homework":
{
"Subject": subject,
"Description": text1,
"Teacher": teacher}
}}
)
WebDriverWait(browser, 250).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]'))).click() # Click on next day button
except:
WebDriverWait(browser, 250).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]'))).click()
except:
try:
date = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))).text)
text = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/p"))).text)
print(date)
print(text)
if collection.find_one({"Date": date}) is None:
collection.insert_one({"Date": date, "Homework": [text]})
else:
collection.update_one(
{"Date": date},
{"$addToSet": {"Homework": text}}
)
WebDriverWait(browser, 250).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]'))).click() # Click on next day button
except:
WebDriverWait(browser, 250).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]'))).click() # Click on next day button
wait_homework()
check_homework()

View File

@@ -1,304 +0,0 @@
# Libraries for open and use Firefox
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
def giorno_cinque(driver, collection):
#Giorno cinque
try:
date = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))).text) # Date
split_date = date.split() # Split date
description = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/p"))).text) # Homework 1 or no homework
mydict = {
"subjects": [
{
"name": "No school subject",
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": "No school subject", "description": description }):
print("Homework already in database")
else:
x = collection.insert_many(mydict) # Insert data in MongoDB
school_subject = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li/h2"))).text) # School subject 1
new_school_subject = {"$set": {"name": school_subject}} # Update school subject
collection.update_one(mydict, new_school_subject) # Update school subject
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict1 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict1) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict2 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict2) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict3 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict3) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict4 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict4) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict5 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict5) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
except TimeoutException:
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/h2"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict6 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict6) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict7 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict7) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict8 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict8) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict9 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict9) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict10 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict10) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button

View File

@@ -1,308 +0,0 @@
from day_five import day_five
# Libraries for open and use Firefox
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
def giorno_quattro(driver, collection):
#Giorno quattro
try:
date = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))).text) # Date
split_date = date.split() # Split date
description = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/p"))).text) # Homework 1 or no homework
mydict = {
"subjects": [
{
"name": "No school subject",
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": "No school subject", "description": description }):
print("Homework already in database")
else:
x = collection.insert_many(mydict) # Insert data in MongoDB
school_subject = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li/h2"))).text) # School subject 1
new_school_subject = {"$set": {"name": school_subject}} # Update school subject
collection.update_one(mydict, new_school_subject) # Update school subject
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict1 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict1) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict2 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict2) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict3 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict3) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict4 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict4) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict5 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict5) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_five.giorno_cinque(driver, collection)
except TimeoutException:
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/h2"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict6 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict6) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict7 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict7) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict8 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict8) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict9 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict9) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict10 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict10) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_five.giorno_cinque(driver, collection)

View File

@@ -1,308 +0,0 @@
from day_two import day_two
# Libraries for open and use Firefox
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
def giorno_uno(driver, collection):
#Giorno uno
try:
date = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))).text) # Date
split_date = date.split() # Split date
description = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/p"))).text) # Homework 1 or no homework
mydict = {
"subjects": [
{
"name": "No school subject",
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": "No school subject", "description": description }):
print("Homework already in database")
else:
x = collection.insert_many(mydict) # Insert data in MongoDB
school_subject = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li/h2"))).text) # School subject 1
new_school_subject = {"$set": {"name": school_subject}} # Update school subject
collection.update_one(mydict, new_school_subject) # Update school subject
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict1 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict1) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict2 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict2) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict3 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict3) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict4 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict4) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict5 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict5) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_two.giorno_due(driver, collection)
except TimeoutException:
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/h2"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict6 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict6) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict7 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict7) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict8 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict8) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict9 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict9) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict10 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict10) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_two.giorno_due(driver, collection)

View File

@@ -1,308 +0,0 @@
from day_four import day_four
# Libraries for open and use Firefox
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
def giorno_tre(driver, collection):
#Giorno tre
try:
date = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))).text) # Date
split_date = date.split() # Split date
description = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/p"))).text) # Homework 1 or no homework
mydict = {
"subjects": [
{
"name": "No school subject",
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": "No school subject", "description": description }):
print("Homework already in database")
else:
x = collection.insert_many(mydict) # Insert data in MongoDB
school_subject = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li/h2"))).text) # School subject 1
new_school_subject = {"$set": {"name": school_subject}} # Update school subject
collection.update_one(mydict, new_school_subject) # Update school subject
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict1 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict1) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict2 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict2) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict3 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict3) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict4 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict4) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict5 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict5) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_four.giorno_quattro(driver, collection)
except TimeoutException:
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/h2"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict6 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict6) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict7 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict7) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict8 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict8) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict9 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict9) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict10 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict10) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_four.giorno_quattro(driver, collection)

View File

@@ -1,308 +0,0 @@
from day_three import day_three
# Libraries for open and use Firefox
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
def giorno_due(driver, collection):
#Giorno due
try:
date = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))).text) # Date
split_date = date.split() # Split date
description = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/p"))).text) # Homework 1 or no homework
mydict = {
"subjects": [
{
"name": "No school subject",
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": "No school subject", "description": description }):
print("Homework already in database")
else:
x = collection.insert_many(mydict) # Insert data in MongoDB
school_subject = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li/h2"))).text) # School subject 1
new_school_subject = {"$set": {"name": school_subject}} # Update school subject
collection.update_one(mydict, new_school_subject) # Update school subject
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict1 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict1) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict2 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict2) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict3 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict3) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict4 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict4) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict5 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict5) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_three.giorno_tre(driver, collection)
except TimeoutException:
try:
school_subject_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/h2"))).text) # School subject 1
description_1 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p"))).text) # Homework 1
mydict6 = {
"subjects": [
{
"name": school_subject_1,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_1,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_1, "description": description_1 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict6) # Insert data in MongoDB
school_subject_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/h2"))).text) # School subject 2
description_2 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p"))).text) # Homework 2
mydict7 = {
"subjects": [
{
"name": school_subject_2,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_2,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_2, "description": description_2 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict7) # Insert data in MongoDB
school_subject_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/h2"))).text) # School subject 3
description_3 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p"))).text) # Homework 3
mydict8 = {
"subjects": [
{
"name": school_subject_3,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_3,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_3, "description": description_3 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict8) # Insert data in MongoDB
school_subject_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/h2"))).text) # School subject 4
description_4 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p"))).text) # Homework 4
mydict9 = {
"subjects": [
{
"name": school_subject_4,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_4,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_4, "description": description_4 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict9) # Insert data in MongoDB
school_subject_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/h2"))).text) # School subject 5
description_5 = str(WebDriverWait(driver, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p"))).text) # Homework 5
mydict10 = {
"subjects": [
{
"name": school_subject_5,
"homework": [
{
"date": {
"long date": date,
"day": split_date[0],
"month": split_date[1],
"year": split_date[2],
},
"description": description_5,
}
]
}
]
},
if collection.find({},{ "_id": 0, "long_date": date ,"name": school_subject_5, "description": description_5 }):
print("Homework already in database")
else:
x = collection.insert_many(mydict10) # Insert data in MongoDB
except TimeoutException:
WebDriverWait(driver, 250).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]"))).click() # Click on next day button
day_three.giorno_tre(driver, collection)

View File

@@ -69,6 +69,6 @@ def check_email():
def send_xlsx():
from update_time_school import update_time_school
update_time_school()
os.remove(f"{DOWNLOAD_FOLDER}/school_time.xlsx") # Delete file
#os.remove(f"{DOWNLOAD_FOLDER}/school_time.xlsx") # Delete file
recheck_email()
check_email()

View File

@@ -1,11 +1,10 @@
from bson.objectid import ObjectId
from openpyxl.styles import NamedStyle
from bson.objectid import ObjectId
from dotenv import load_dotenv
import openpyxl as xl
import datetime
import pymongo
import urllib
import datetime
import os
load_dotenv() #Load .env file
@@ -450,12 +449,9 @@ def update_time_school():
number_teacher = 1
number_room = 1
number = 1
current_day = None
day_counter = 0
number_day = 0
#Search my class in excel file and add in MongoDB
number = 1
gagaga = 0
#Search my class in excel file and add in MongoDB
for row in range (1, 100):
# column B ~ column F
for column in range (1, 100):
@@ -465,16 +461,18 @@ def update_time_school():
for i in range(4,80):
day = str(ws.cell(row=i, column=3).value) # Get day from excel file
school_subject = ws.cell(row=i, column=column).value # Get school subject from excel file
teacher = ws.cell(row=i, column=column+1).value
room = ws.cell(row=i, column=column+2).value
teacher = ws.cell(row=i, column=column+1).value # Get teacher from excel file
room = ws.cell(row=i, column=column+2).value # Get room from excel file
# Simple counter for don't repeat
if dont_repeat == 9:
check_repeat += 1
if check_repeat == 5:
check_repeat = 0
dont_repeat = 0
else:
if day == "None":
if school_subject == 0: #If school subject is 0, add "" in MongoDB
if day == "None": #If day is None, don't add a school subject in MongoDB
if school_subject == 0 or school_subject == "0": #If school subject is 0, add "" in MongoDB
number += 1
gagaga += 1
dont_repeat += 1
@@ -488,6 +486,8 @@ def update_time_school():
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
array_document_school_time_table = find_document_school_time_table[0]["_id"]
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
# Shorten school subject name
if remove_things_in_front == "MISURE ELETTRICHE":
remove_things_in_front = "MISURE"
elif remove_things_in_front == " EDUCAZIONE ATTIVITA' MOTORIE":
@@ -504,16 +504,17 @@ def update_time_school():
remove_things_in_front = "INGLESE"
elif remove_things_in_front == "SCIENZE INTEGRATE - FISICA":
remove_things_in_front = "FISICA"
elif remove_things_in_front == "21PM2 LABORATORIO ELETTRICO":
remove_things_in_front == "LAB. ELETTRICO"
# Add school subject in MongoDB beacause school subject is not 0
collection.update_one(
collection.update_one( # Add school subject in MongoDB beacause school subject is not 0
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": remove_things_in_front,
}
}
)
collection_archive.update_one(
collection_archive.update_one( # Add school subject in MongoDB (archive) beacause school subject is not 0
{ "_id": ObjectId(array_document_archive_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": remove_things_in_front,
@@ -523,29 +524,30 @@ def update_time_school():
number += 1
gagaga += 1
dont_repeat += 1
# Simple counter for don't repeat
if number == 9:
number = 1
if gagaga == 8:
gagaga = 0
else:
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
array_test = []
array_test.append(convert_date_to_day)
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y") # Convert date to day
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A') # Convert date to day
array_test = [] # Create array
array_test.append(convert_date_to_day) # Add day in array
number_day += 1
if school_subject == 0: #If school subject is 0, add "" in MongoDB
if school_subject == 0 or school_subject == "0": #If school subject is 0, add "" in MongoDB
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
array_document_school_time_table = find_document_school_time_table[0]["_id"]
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
collection.update_one(
collection.update_one( # Add "" in MongoDB beacause school subject is 0
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": remove_things_in_front,
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
}
}
)
collection_archive.update_one(
collection_archive.update_one( # Add "" in MongoDB (archive) beacause school subject is 0
{ "_id": ObjectId(array_document_archive_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
@@ -562,42 +564,39 @@ def update_time_school():
if gagaga == 8:
gagaga = 0
else: #If school subject is not 0, add school subject in MongoDB
if school_subject == "21PM1 MISURE ELETTRICHE":
if school_subject == "MISURE ELETTRICHE":
school_subject = "MISURE"
elif school_subject == " CEAM EDUCAZIONE ATTIVITA' MOTORIE":
elif school_subject == " EDUCAZIONE ATTIVITA' MOTORIE":
school_subject = "MOTORIA"
elif school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE":
school_subject = "MOTORIA"
elif school_subject == "CSGGE1 DIRITTO ED ECONOMIA":
elif school_subject == "EDUCAZIONE ATTIVITA' MOTORIE":
school_subject = "Motoria"
elif school_subject == "DIRITTO ED ECONOMIA":
school_subject = "DIRITTO"
elif school_subject == "PR1 INGLESE PROFESSIONALE":
elif school_subject == "INGLESE PROFESSIONALE":
school_subject = "INGLESE PRO."
elif school_subject == "PR1 LABORATORIO ELETTRICO":
elif school_subject == "LABORATORIO ELETTRICO":
school_subject = "LAB. ELETTRICO"
elif school_subject == "CLING LINGUA INGLESE":
elif school_subject == "LINGUA INGLESE":
school_subject = "INGLESE"
elif school_subject == "CMST2 SCIENZE INTEGRATE - FISICA":
elif school_subject == "SCIENZE INTEGRATE - FISICA":
school_subject = "FISICA"
elif school_subject == "PR1 DISEGNO":
school_subject = "DISEGNO"
elif school_subject == "CSGGE2 STORIA":
school_subject = "STORIA"
elif school_subject == "CMST1 MATEMATICA":
school_subject = "MATEMATICA"
elif school_subject == "21PM2 LABORATORIO ELETTRICO":
school_subject == "LAB. ELETTRICO"
# Search document on MongoDB
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
array_document_school_time_table = find_document_school_time_table[0]["_id"]
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
# Add school subject in MongoDB beacause school subject is not 0
collection.update_one(
collection.update_one( # Add school subject in MongoDB beacause school subject is not 0
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
}
}
)
collection_archive.update_one(
collection_archive.update_one( # Add school subject in MongoDB (archive) beacause school subject is not 0
{ "_id": ObjectId(array_document_archive_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
@@ -607,6 +606,7 @@ def update_time_school():
number += 1
gagaga += 1
dont_repeat += 1
# Simple counter for don't repeat
if number == 9:
number = 1
if gagaga == 8:
@@ -618,10 +618,10 @@ def update_time_school():
if check_repeat_teacher == 5:
check_repeat_teacher = 0
dont_repeat_teacher = 0
#number = 1
else:
if day == "None":
if teacher == 0:
if day == "None": # Check if day is None
if teacher == 0: # Check if teacher is 0
# If teacher is 0, add anything in MongoDB
number_teacher += 1
gagaga_teacher += 1
dont_repeat_teacher += 1
@@ -630,18 +630,20 @@ def update_time_school():
if gagaga_teacher == 9:
gagaga_teacher = 0
else:
# Search document on MongoDB
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
array_document_school_time_table = find_document_school_time_table[0]["_id"]
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
collection.update_one(
collection.update_one( # Add teacher in MongoDB beacause teacher is not 0
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_teacher) + ".Teacher": teacher,
}
}
)
collection_archive.update_one(
collection_archive.update_one( # Add teacher in MongoDB (archive) beacause teacher is not 0
{ "_id": ObjectId(array_document_archive_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_teacher)+ ".Teacher": teacher,
@@ -656,22 +658,25 @@ def update_time_school():
if gagaga_teacher == 8:
gagaga_teacher = 0
else:
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
array_test = []
array_test.append(convert_date_to_day)
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y") # Convert date to day
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A') # Convert date to day
array_test = [] # Create array
array_test.append(convert_date_to_day) # Add day in array
# Search document on MongoDB
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
array_document_school_time_table = find_document_school_time_table[0]["_id"]
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
collection.update_one(
collection.update_one( # Add teacher in MongoDB beacause teacher is not 0
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_teacher)+ ".Teacher": teacher,
}
}
)
collection_archive.update_one(
collection_archive.update_one( # Add teacher in MongoDB (archive) beacause teacher is not 0
{ "_id": ObjectId(array_document_archive_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_teacher)+ ".Teacher": teacher,
@@ -681,6 +686,7 @@ def update_time_school():
number_teacher += 1
gagaga_teacher += 1
dont_repeat_teacher += 1
# Simple counter for don't repeat
if number_teacher == 9:
number_teacher = 1
if gagaga_teacher == 8:
@@ -693,7 +699,7 @@ def update_time_school():
check_repeat_room = 0
dont_repeat_room = 0
else:
if day == "None":
if day == "None": # Check if day is None
if room == 0:
number_room += 1
gagaga_room += 1
@@ -703,18 +709,20 @@ def update_time_school():
if gagaga_room == 9:
gagaga_room = 0
else:
# Search document on MongoDB
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
array_document_school_time_table = find_document_school_time_table[0]["_id"]
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
collection.update_one(
collection.update_one( # Add room in MongoDB beacause room is not 0
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_room) + ".Room": room,
}
}
)
collection_archive.update_one(
collection_archive.update_one( # Add room in MongoDB (archive) beacause room is not 0
{ "_id": ObjectId(array_document_archive_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_room)+ ".Room": room,
@@ -724,27 +732,32 @@ def update_time_school():
number_room += 1
gagaga_room += 1
dont_repeat_room += 1
# Simple counter for don't repeat
if number_room == 9:
number_room = 1
if gagaga_room == 8:
gagaga_room = 0
else:
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
array_test = []
array_test.append(convert_date_to_day)
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y") # Convert date to day
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
array_test = [] # Create array
array_test.append(convert_date_to_day) # Add day in array
# Search document on MongoDB
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
array_document_school_time_table = find_document_school_time_table[0]["_id"]
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
collection.update_one(
collection.update_one( # Add room in MongoDB beacause room is not 0
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_room)+ ".Room": room,
}
}
)
collection_archive.update_one(
collection_archive.update_one( # Add room in MongoDB (archive) beacause room is not 0
{ "_id": ObjectId(array_document_archive_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_room)+ ".Room": room,
@@ -754,23 +767,23 @@ def update_time_school():
number_room += 1
gagaga_room += 1
dont_repeat_room += 1
# Simple counter for don't repeat
if number_room == 9:
number_room = 1
if gagaga_room == 8:
gagaga_room = 0
# Look for other classes doing PE at the same time as us
if school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIA":
if school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIA":
for c in range(1,100):
search_motoria = ws.cell(row=i, column=c).value
#print(search_motoria)
if search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIA":
if c == column:
pass
else:
search_class = ws.cell(row=3, column=c).value
print(search_class)
collection.update_one(
search_class = ws.cell(row=3, column=c).value # Search class
collection.update_one( # Add class in MongoDB
{ "_id": ObjectId(array_document_school_time_table)},
{ "$set": {
"School Subject." + array_test[0] + "." + str(gagaga_room-1)+ ".PE with": search_class,
@@ -783,7 +796,6 @@ def update_time_school():
# Search if class le3 is busy
for c in range(1,100):
search_other_subject = ws.cell(row=i, column=c).value
search_room = ws.cell(row=i, column=c).value
if c == column:
pass
else:
@@ -814,5 +826,44 @@ def update_time_school():
)
else:
pass
#
docs = collection.find()
# 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):
pomate = doc["School Subject"][day[i]][0]['Subject']
try:
remove_things_in_front = pomate.split(' ', 1)[1]
if remove_things_in_front == "ITALIANA":
collection.update_one(
{ "_id": ObjectId(doc_id)},
{ "$set": {
"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",
}
}
)
else:
collection.update_one(
{ "_id": ObjectId(doc_id)},
{ "$set": {
"School Subject." + day[i] + ".0.Subject": remove_things_in_front,
}
}
)
except:
pass
update_time_school()