Optimization of code for tasks.

TO-DO Send all data to MongoDB
This commit is contained in:
Stefano Assenzo 2023-03-25 11:19:10 +00:00 committed by GitHub
parent 34d18eb4ed
commit 815f3fc0d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 1330 deletions

View File

@ -1,62 +1,89 @@
# Import file for check homework import pymongo
from day_one import day_one from selenium import webdriver
# Libraries for open and use Firefox
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.firefox.options import Options from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Libraries for MongoDB and .env file
from dotenv import load_dotenv
import urllib.parse
import datetime import datetime
import pymongo from dotenv import load_dotenv
import time
import os 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 load_dotenv() #Load .env file
USERNAME = os.getenv('USERNAME_NUVOLA') #Username for Nuvola USERNAME = os.getenv('USERNAME_NUVOLA') #Username for Nuvola
PASSWORD = os.getenv('PASSWORD_NUVOLA') #Password for Nuvola PASSWORD = os.getenv('PASSWORD_NUVOLA') #Password for Nuvola
PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
URL_MONGODB = os.getenv('URL_MONGODB') #URL 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) 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 client = pymongo.MongoClient(mongo_url) #Connect to MongoDB
database = client["website-class"] #Database name db = client["website-class"]
collection = database["homework"] #Collection school time table current
# Options for Firefox # Get today's date as a string in the format "YYYY-MM-DD"
options = Options() # Set options today = datetime.datetime.now().strftime("%Y-%m-%d")
options.add_argument("--headless") # Headless mode (so you don't see the browser)
options.add_argument('--disable-gpu') # Disable GPU
def start_search(): # Get the collection for today's data
#time.sleep(7200) collection = db["homework"]
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
username.click() # Initialize the URL for Cloud
username.clear() url = 'https://nuvola.madisoft.it/login'
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
# Section Homework browser.get(url)
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 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
homework_check() 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(): # Click on the "Next Day" button to go to the next day's tasks
day_one.giorno_uno(driver, collection) 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]')))
driver.close()
print("Finish")
start_search()
start_search() def wait_recheck():
time.sleep(10800)
def check_homework():
for i in range(1, 10):
try:
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(text1)
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(text1)
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(text1)
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(text1)
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(text1)
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:
try:
text = str(WebDriverWait(browser, 250).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div/div/main/div/p"))).text)
print(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
browser.quit()
wait_recheck()
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,58 +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 insert_homework_to_mongo(collection, school_subject, date, description):
# Check if homework already exists in the collection
if collection.find_one({"long_date": date, "name": school_subject, "description": description}):
print("Homework already in database")
else:
# Create dictionary for MongoDB document
mydict = {
"name": school_subject,
"date": {
"long_date": date,
"day": date.split()[0],
"month": date.split()[1],
"year": date.split()[2]
},
"description": description
}
# Insert document into MongoDB
x = collection.insert_one(mydict)
print("Homework inserted into database")
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
# Insert homework for "No school subject"
insert_homework_to_mongo(collection, "No school subject", date, description)
# Loop through all school subjects and insert homework for each
school_subjects = driver.find_elements_by_xpath("/html/body/div/div/main/div/div[2]/div/ul/li")
for subject in school_subjects:
school_subject = str(subject.find_element_by_xpath("./h2").text)
homework = subject.find_element_by_xpath("./div/ul/li/p").text
# Insert homework for current school subject
insert_homework_to_mongo(collection, school_subject, date, homework)
try:
# Click on next day button
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()
# Call giorno_due() function from day_two.py for next day
day_two.giorno_due(driver, collection)
except TimeoutException:
# No more days to scrape, end function
pass
except:
print("Error")

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)