Compare commits

..

21 Commits

Author SHA1 Message Date
583487d204 Fix bug Bot Telegram 2023-09-29 16:34:24 +02:00
Stefano Assenzo
9bbe459585 Fix little things 2023-03-31 16:20:24 +00:00
Stefano Assenzo
62b9c93a2c Fix bot Discord and add new command for send image school time table - Finish upload homework on MongoDB (there is a small bug but it is not a big deal) 2023-03-25 16:43:20 +00:00
Stefano Assenzo
815f3fc0d6 Optimization of code for tasks.
TO-DO Send all data to MongoDB
2023-03-25 11:19:10 +00:00
Stefano Assenzo
34d18eb4ed Fix little bug on Discord bot 2023-03-24 16:38:22 +00:00
Stefano Assenzo
7fdc771d52 Bugs fixed in school schedule generation, add new option on Discord bot 2023-03-24 16:00:55 +00:00
Stefano Assenzo
efa9348cfd Merge branch 'dev' of https://github.com/assenzostefano/class-website into dev 2023-03-11 18:04:40 +00:00
Stefano Assenzo
660dfa283a So now? 2023-03-11 18:04:16 +00:00
Stefano Assenzo
fb2df8c658 Update main.py 2023-03-11 19:03:41 +01:00
Stefano Assenzo
792be8591b Update main.py 2023-03-11 18:33:05 +01:00
Stefano Assenzo
f336cffa60 Update main.py 2023-03-11 10:19:13 +01:00
Stefano Assenzo
2b7665f8ad Update main.py 2023-03-10 20:06:03 +01:00
Stefano Assenzo
4e0e1c545f Update main.py 2023-03-10 20:04:54 +01:00
Stefano Assenzo
9894a6957c Update main.py 2023-03-07 15:45:34 +01:00
Stefano Assenzo
f7f9181c6c Update main.py 2023-03-07 15:45:15 +01:00
Stefano Assenzo
0e77be9e07 Update main.py 2023-03-07 15:41:00 +01:00
Stefano Assenzo
c9e971c6bf Update main.py 2023-03-07 10:57:12 +01:00
Stefano Assenzo
03dc72fdc6 Update main.py 2023-03-07 07:57:25 +01:00
Stefano Assenzo
d8db86a33d ehi 2023-03-06 16:07:05 +00:00
Stefano Assenzo
f19d664646 So now? 2023-03-06 16:06:59 +00:00
Stefano Assenzo
2c78f7ed1e Everything should be right now 2023-03-06 16:02:21 +00:00
12 changed files with 340 additions and 1363 deletions

3
.gitignore vendored
View File

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

7
app.py
View File

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

View File

@@ -1,4 +1,4 @@
from commands.moderation import ban, kick, clear_msg
#from commands.moderation import ban, kick, clear_msg
from discord.commands.context import ApplicationContext # Discord
from selenium.webdriver.firefox.options import Options # Selenium
from discord.commands import Option # Discord
@@ -44,18 +44,19 @@ bot = discord.Bot()
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
bot.loop.create_task(orario())
orario.start()
# Search on MongoDB the subject and send a message on Discord if the subject is found
@tasks.loop(seconds=1)
@tasks.loop(seconds=10)
async def orario():
documents = collection.find()
send_screenshot = 0
print("Searching for subject...")
# Iterate through the documents
for document in documents:
for day in document['School Subject']:
for i, subject in enumerate(document['School Subject'][day]):
if subject['Subject'] == "CALF1 LINGUA ITALIANA":
if subject['Subject'] == "LINGUA ITALIANA" or "ITALIANA":
# Send a message on channel #general with the subject found and the index of the subject
options = Options() # Set options
options.add_argument("--headless") # Headless mode (so you don't see the browser)
@@ -64,17 +65,31 @@ async def orario():
driver = webdriver.Firefox(options=options)
driver.get('http://127.0.0.1:4999/orario')
time.sleep(5)
driver.get_screenshot_as_file("screenshot.png")
driver.quit()
channel = bot.get_channel(GENERAL_ID)
channel = bot.get_channel(int(GENERAL_ID))
await channel.send(file=discord.File("screenshot.png"))
os.remove("screenshot.png")
send_screenshot += 1
else:
pass
channel = bot.get_channel(GENERAL_ID)
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']} at index: {i}")
if i == 0:
i = "First hour"
elif i == 1:
i = "Second hour"
elif i == 2:
i = "Third hour"
elif i == 3:
i = "Fourth hour"
elif i == 4:
i = "Fifth hour"
elif i == 5:
i = "Sixth hour"
elif i == 6:
i = "Seventh hour"
elif i == 7:
i = "Eighth hour"
await channel.send(f"Day: {day}, Hour school: {i}, Subject found: {subject['Subject']}")
send_screenshot = 0
@@ -90,10 +105,18 @@ async def change_school_time(
"Select hour school",
choices=["First hour", "Second hour", "Third hour", "Fourth hour", "Fifth hour", "Sixth hour", "Seventh hour", "Eighth hour", "Ninth hour"],
required=True,
), text: str
), text: str,
teacher: Option(str,
"Write teacher",
required=False,
),
room: Option(str,
"Write room school",
required=False,
),
):
await ctx.respond(f"Day selected: {day}, Hour school selected: {hour_school}, Text: {text}")
await ctx.respond(f"Day selected: {day}, Hour school selected: {hour_school}, Text: {text}, Teacher: {teacher} ,Room: {room}")
# Update the subject on MongoDB
if hour_school == "First hour":
hour_school = "0"
@@ -121,10 +144,32 @@ async def change_school_time(
{"$set": {f"School Subject.{day}.{int(hour_school)}.Subject": text}}
)
if teacher != None:
collection.update_one(
{"_id": ObjectId(array_document)},
{"$set": {f"School Subject.{day}.{int(hour_school)}.Teacher": teacher}}
)
if room != None:
collection.update_one(
{"_id": ObjectId(array_document)},
{"$set": {f"School Subject.{day}.{int(hour_school)}.Room": room}}
)
@bot.slash_command(name='confirm', description='Confirm change school time')
async def confirm(ctx : ApplicationContext):
await ctx.respond(f"Confirm")
collection_email.update_one({}, {"$set": {"Send on Whatsapp": "yes"}})
options = Options() # Set options
options.add_argument("--headless") # Headless mode (so you don't see the browser)
options.add_argument('--disable-gpu') # Disable GPU
driver = webdriver.Firefox(options=options)
driver.get('http://127.0.0.1:4999/orario')
driver.get_screenshot_as_file("screenshot.png")
driver.quit()
channel = bot.get_channel(int(GENERAL_ID))
await channel.send(file=discord.File("screenshot.png"))
os.remove("screenshot.png")
#@bot.slash_command()
#@discord.default_permissions(ban_members = True, administrator = True)
#async def ban(ctx, member: Option(discord.Member, description="Select a member", required=True), reason: Option(str, description="Reason", required=True)):
@@ -141,4 +186,6 @@ async def confirm(ctx : ApplicationContext):
#async def clear(ctx, messages: Option(int, description="Amount of messages to delete", required=True)):
# clear_msg.clear_messages(ctx, amount = messages)
bot.run(DISCORD_TOKEN)
while True:
bot.run(DISCORD_TOKEN)
orario.start()

View File

@@ -1,12 +1,14 @@
from bson.objectid import ObjectId
from dotenv import load_dotenv
from telebot import telebot
import threading
import time
import datetime
import threading
import time
import schedule
import pymongo
import urllib
import time
import pytz
import os
load_dotenv()
@@ -38,10 +40,6 @@ def subscribe(message):
)
bot.send_message(message.chat.id, "You are subscribed")
def recheck():
time.sleep(60)
send_notification()
def send_notification():
today = datetime.datetime.today().strftime('%A')
tomorrow = (datetime.datetime.today() + datetime.timedelta(days=1)).strftime('%A')
@@ -49,7 +47,7 @@ def send_notification():
if today == "Saturday" or today == "Sunday":
print("Today is weekend")
else:
# Alla prima ora (7.50) manda una notifica a tutti gli utenti che hanno scritto /subscribe della materia della prima ora e così via
# Alla prima ora (7.50) manda una notifica a tutti gli utenti che hanno scritto /subscribe della materia della prima ora
find_document = list(collection_schooltime.find({}, {"_id": 0, "School Subject": 1}))
collection_find_username = list(collection.find({}, {"username": 1,})) #Find all username in collection
array_username = collection_find_username[0]["username"] #Array with all username
@@ -58,46 +56,53 @@ def send_notification():
if now.strftime("%H:%M") == "07:50":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][0]['Room']) + ", " + i['School Subject'][today][0]['Teacher'] + ", " + i['School Subject'][today][0]['Subject'] + "\n" + "Successiva: " + str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + i['School Subject'][today][1]['Subject'])
recheck()
bot.send_message(b, str(i['School Subject'][today][0]['Room']) + ", " + i['School Subject'][today][0]['Teacher'] + ", " + i['School Subject'][today][0]['Subject'] + "\n" + "Successiva: " + str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + i['School Subject'][today][1]['Subject'])
elif now.strftime("%H:%M") == "08:50":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + str(i['School Subject'][today][1]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + i['School Subject'][today][2]['Subject'])
recheck()
bot.send_message(b, str(i['School Subject'][today][1]['Room']) + ", " + i['School Subject'][today][1]['Teacher'] + ", " + str(i['School Subject'][today][1]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + i['School Subject'][today][2]['Subject'])
elif now.strftime("%H:%M") == "09:50":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + str(i['School Subject'][today][2]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][3]['Room']) + ", " + i['School Subject'][today][3]['Teacher'] + ", " + i['School Subject'][today][3]['Subject'])
recheck()
bot.send_message(b, str(i['School Subject'][today][2]['Room']) + ", " + i['School Subject'][today][2]['Teacher'] + ", " + str(i['School Subject'][today][2]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][3]['Room']) + ", " + i['School Subject'][today][3]['Teacher'] + ", " + i['School Subject'][today][3]['Subject'])
elif now.strftime("%H:%M") == "11:05":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][3]['Room']) + ", " + i['School Subject'][today][3]['Teacher'] + ", " + str(i['School Subject'][today][3]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][4]['Room']) + ", " + i['School Subject'][today][4]['Teacher'] + ", " + i['School Subject'][today][4]['Subject'])
recheck()
elif now.strftime("%H:%M") == "12:05":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][4]['Room']) + ", " + i['School Subject'][today][4]['Teacher'] + ", " + str(i['School Subject'][today][4]['Subject']) + "\n" + "Successiva: " + str(i['School Subject'][today][5]['Room']) + ", " + i['School Subject'][today][5]['Teacher'] + ", " + i['School Subject'][today][5]['Subject'])
recheck()
elif now.strftime("%H:%M") == "13:05":
for i in find_document:
for b in array_username:
bot.send_message(b, str(i['School Subject'][today][5]['Room']) + ", " + i['School Subject'][today][5]['Teacher'] + ", " + str(i['School Subject'][today][5]['Subject']))
recheck()
elif now.strftime("%H:%M") == "21:00":
if tomorrow == "Sunday" or tomorrow == "Saturday":
print("Nope")
if tomorrow == "Monday":
for i in find_document:
for b in array_username:
bot.send_message(b, i['School Subject'][tomorrow][0]['Subject'] + ", " + i['School Subject'][tomorrow][0]['Teacher'] + "\n" + i['School Subject'][tomorrow][1]['Subject'] + ", " + i['School Subject'][tomorrow][1]['Teacher'] + "\n" + i['School Subject'][tomorrow][2]['Subject'] + ", " + i['School Subject'][tomorrow][2]['Teacher'] + "\n" + i['School Subject'][tomorrow][3]['Subject'] + ", " + i['School Subject'][tomorrow][3]['Teacher'] + "\n" + i['School Subject'][tomorrow][4]['Subject'] + ", " + i['School Subject'][tomorrow][4]['Teacher'] + "\n" + i['School Subject'][tomorrow][5]['Subject'] + ", " + i['School Subject'][tomorrow][5]['Teacher'])
else:
for i in find_document:
for b in array_username:
bot.send_message(b, i['School Subject'][tomorrow][0]['Subject'] + ", " + i['School Subject'][tomorrow][0]['Teacher'] + "\n" + i['School Subject'][tomorrow][1]['Subject'] + ", " + i['School Subject'][tomorrow][1]['Teacher'] + "\n" + i['School Subject'][tomorrow][2]['Subject'] + ", " + i['School Subject'][tomorrow][2]['Teacher'] + "\n" + i['School Subject'][tomorrow][3]['Subject'] + ", " + i['School Subject'][tomorrow][3]['Teacher'] + "\n" + i['School Subject'][tomorrow][4]['Subject'] + ", " + i['School Subject'][tomorrow][4]['Teacher'] + "\n" + i['School Subject'][tomorrow][5]['Subject'] + ", " + i['School Subject'][tomorrow][5]['Teacher'])
else:
recheck()
def test_time():
print("Test")
schedule.every().day.at("07:50").do(send_notification)
schedule.every().day.at("08:50").do(send_notification)
schedule.every().day.at("09:50").do(send_notification)
schedule.every().day.at("11:05").do(send_notification)
schedule.every().day.at("12:05").do(send_notification)
schedule.every().day.at("13:05").do(send_notification)
schedule.every().day.at("21:05").do(send_notification)
tz = pytz.timezone("Europe/Rome")
now = datetime.datetime.now()
t1 = threading.Thread(target=bot.polling).start()
while True:
schedule.run_pending()
time.sleep(10)
print(now)
schedule.run_pending()

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,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)

View File

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