From 0f8a83c9c588f7329acd0b0db83db74ecebf7906 Mon Sep 17 00:00:00 2001 From: Stefano Assenzo Date: Sat, 14 Jan 2023 15:23:00 +0000 Subject: [PATCH] Now before uploading tasks to MongoDB check if they have already been uploaded --- src/events/homework/check_homework.py | 6 +- src/events/homework/day_five/day_five.py | 69 ++- src/events/homework/day_four/day_four.py | 69 ++- src/events/homework/day_one/day_one.py | 67 ++- src/events/homework/day_three/day_three.py | 69 ++- src/events/homework/day_two/day_two.py | 507 +++++++++++---------- 6 files changed, 502 insertions(+), 285 deletions(-) diff --git a/src/events/homework/check_homework.py b/src/events/homework/check_homework.py index 25fc7c0..0d7e896 100644 --- a/src/events/homework/check_homework.py +++ b/src/events/homework/check_homework.py @@ -12,6 +12,7 @@ from selenium import webdriver from dotenv import load_dotenv import urllib.parse import pymongo +import time import os #Load .env file @@ -31,6 +32,7 @@ options.add_argument("--headless") # Headless mode (so you don't see the browser options.add_argument('--disable-gpu') # Disable GPU 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 @@ -50,9 +52,9 @@ def start_search(): homework_check() def homework_check(): - #Giorno uno - day_five.giorno_cinque(driver, collection) + day_one.giorno_uno(driver, collection) driver.close() start_search() + print("Finish") start_search() \ No newline at end of file diff --git a/src/events/homework/day_five/day_five.py b/src/events/homework/day_five/day_five.py index d1b4ee1..571d904 100644 --- a/src/events/homework/day_five/day_five.py +++ b/src/events/homework/day_five/day_five.py @@ -17,6 +17,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -27,11 +28,13 @@ def giorno_cinque(driver, collection): } ] }, - - x = collection.insert_many(mydict) # Insert data in MongoDB + 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": {"School Subject": school_subject}} # Update school subject + 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 @@ -43,6 +46,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -54,7 +58,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict1) # Insert data in MongoDB + 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 @@ -65,6 +72,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -76,7 +84,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict2) # Insert data in MongoDB + 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 @@ -87,6 +98,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -98,7 +110,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict3) # Insert data in MongoDB + 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 @@ -109,6 +124,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -120,7 +136,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict4) # Insert data in MongoDB + 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 @@ -131,6 +150,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -142,7 +162,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict5) # Insert data in MongoDB + 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 @@ -157,6 +180,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -168,7 +192,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict6) # Insert data in MongoDB + 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 @@ -179,6 +206,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -190,7 +218,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict7) # Insert data in MongoDB + 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 @@ -201,6 +232,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -212,7 +244,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict8) # Insert data in MongoDB + 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 @@ -223,6 +258,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -234,7 +270,10 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict9) # Insert data in MongoDB + 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 @@ -245,6 +284,7 @@ def giorno_cinque(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -256,6 +296,9 @@ def giorno_cinque(driver, collection): ] }, - x = collection.insert_many(mydict10) # Insert data in MongoDB + 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 \ No newline at end of file diff --git a/src/events/homework/day_four/day_four.py b/src/events/homework/day_four/day_four.py index 8c65b24..4399842 100644 --- a/src/events/homework/day_four/day_four.py +++ b/src/events/homework/day_four/day_four.py @@ -19,6 +19,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -29,11 +30,13 @@ def giorno_quattro(driver, collection): } ] }, - - x = collection.insert_many(mydict) # Insert data in MongoDB + 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": {"School Subject": school_subject}} # Update school subject + 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 @@ -45,6 +48,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -56,7 +60,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict1) # Insert data in MongoDB + 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 @@ -67,6 +74,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -78,7 +86,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict2) # Insert data in MongoDB + 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 @@ -89,6 +100,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -100,7 +112,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict3) # Insert data in MongoDB + 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 @@ -111,6 +126,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -122,7 +138,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict4) # Insert data in MongoDB + 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 @@ -133,6 +152,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -144,7 +164,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict5) # Insert data in MongoDB + 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 @@ -160,6 +183,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -171,7 +195,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict6) # Insert data in MongoDB + 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 @@ -182,6 +209,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -193,7 +221,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict7) # Insert data in MongoDB + 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 @@ -204,6 +235,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -215,7 +247,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict8) # Insert data in MongoDB + 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 @@ -226,6 +261,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -237,7 +273,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict9) # Insert data in MongoDB + 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 @@ -248,6 +287,7 @@ def giorno_quattro(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -259,7 +299,10 @@ def giorno_quattro(driver, collection): ] }, - x = collection.insert_many(mydict10) # Insert data in MongoDB + 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) \ No newline at end of file diff --git a/src/events/homework/day_one/day_one.py b/src/events/homework/day_one/day_one.py index c047671..d8a8301 100644 --- a/src/events/homework/day_one/day_one.py +++ b/src/events/homework/day_one/day_one.py @@ -19,6 +19,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -29,8 +30,10 @@ def giorno_uno(driver, collection): } ] }, - - x = collection.insert_many(mydict) # Insert data in MongoDB + 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 @@ -45,6 +48,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -56,7 +60,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict1) # Insert data in MongoDB + 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 @@ -67,6 +74,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -78,7 +86,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict2) # Insert data in MongoDB + 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 @@ -89,6 +100,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -100,7 +112,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict3) # Insert data in MongoDB + 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 @@ -111,6 +126,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -122,7 +138,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict4) # Insert data in MongoDB + 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 @@ -133,6 +152,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -144,7 +164,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict5) # Insert data in MongoDB + 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 @@ -160,6 +183,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -171,7 +195,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict6) # Insert data in MongoDB + 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 @@ -182,6 +209,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -193,7 +221,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict7) # Insert data in MongoDB + 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 @@ -204,6 +235,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -215,7 +247,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict8) # Insert data in MongoDB + 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 @@ -226,6 +261,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -237,7 +273,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict9) # Insert data in MongoDB + 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 @@ -248,6 +287,7 @@ def giorno_uno(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -259,7 +299,10 @@ def giorno_uno(driver, collection): ] }, - x = collection.insert_many(mydict10) # Insert data in MongoDB + 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) \ No newline at end of file diff --git a/src/events/homework/day_three/day_three.py b/src/events/homework/day_three/day_three.py index 5e8cf5f..d78d2fd 100644 --- a/src/events/homework/day_three/day_three.py +++ b/src/events/homework/day_three/day_three.py @@ -19,6 +19,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -29,11 +30,13 @@ def giorno_tre(driver, collection): } ] }, - - x = collection.insert_many(mydict) # Insert data in MongoDB + 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": {"School Subject": school_subject}} # Update school subject + 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 @@ -45,6 +48,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -56,7 +60,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict1) # Insert data in MongoDB + 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 @@ -67,6 +74,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -78,7 +86,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict2) # Insert data in MongoDB + 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 @@ -89,6 +100,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -100,7 +112,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict3) # Insert data in MongoDB + 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 @@ -111,6 +126,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -122,7 +138,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict4) # Insert data in MongoDB + 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 @@ -133,6 +152,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -144,7 +164,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict5) # Insert data in MongoDB + 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 @@ -160,6 +183,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -171,7 +195,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict6) # Insert data in MongoDB + 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 @@ -182,6 +209,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -193,7 +221,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict7) # Insert data in MongoDB + 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 @@ -204,6 +235,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -215,7 +247,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict8) # Insert data in MongoDB + 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 @@ -226,6 +261,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -237,7 +273,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict9) # Insert data in MongoDB + 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 @@ -248,6 +287,7 @@ def giorno_tre(driver, collection): "homework": [ { "date": { + "long date": date, "day": split_date[0], "month": split_date[1], "year": split_date[2], @@ -259,7 +299,10 @@ def giorno_tre(driver, collection): ] }, - x = collection.insert_many(mydict10) # Insert data in MongoDB + 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) \ No newline at end of file diff --git a/src/events/homework/day_two/day_two.py b/src/events/homework/day_two/day_two.py index e848f6f..d8d44db 100644 --- a/src/events/homework/day_two/day_two.py +++ b/src/events/homework/day_two/day_two.py @@ -8,258 +8,301 @@ 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": [ + 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": [ { - "name": "No school subject", - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description, - } - ] - } - ] - }, - + "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": {"School Subject": 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": [ + + 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": [ { - "name": school_subject_1, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_1, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_2, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_2, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_3, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_3, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_4, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_5, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_5, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_5, - } - ] - } - ] - }, - + "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": [ + 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": [ { - "name": school_subject_1, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_1, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_2, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_2, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_3, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_3, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_4, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_4, - } - ] - } - ] - }, - + "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": [ + + 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": [ { - "name": school_subject_5, - "homework": [ - { - "date": { - "day": split_date[0], - "month": split_date[1], - "year": split_date[2], - }, - "description": description_5, - } - ] - } - ] - }, - + "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) \ No newline at end of file + 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) \ No newline at end of file