Compare commits

..

No commits in common. "f7ce81ef5d775d943ede3757fdcc6dfa59c2b2b6" and "607d3715348eb94620ea3e1dace2a10721c1a57d" have entirely different histories.

5 changed files with 29 additions and 134 deletions

View File

@ -1,15 +1,8 @@
# Databse (MongoDB)
PASSWORD_MONGODB = ""
URL_MONGODB = ""
# Email
IMAP_SERVER = ""
SMTP_PORT = ""
EMAIL = ""
PWD_EMAIL = ""
EMAIL = "
SMTP_SERVER = ""
SMTP_PORT = ""
EMAIL_SCHOOL = ""
DOWNLOAD_FOLDER = ""
# Nuvola
USERNAME_NUVOLA = ""
PASSWORD_NUVOLA = ""
DOWNLOAD_FOLDER = ""

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
test.xlsx
.env
geckodriver.log
all.log
geckodriver.log

16
app.py
View File

@ -1,26 +1,14 @@
from flask import Flask, render_template, request, session, jsonify
import requests
import logging
import bcrypt
import sys
import os
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.FileHandler("src/log/all.log"),
logging.StreamHandler(sys.stdout)
]
)
app = Flask(__name__)
IMAGE_FOLDER = os.path.join('static', 'images')
app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER
@app.route('/')
def homepage():
logging.info("A user went up: Homepage")
return render_template('html/index.html')
#imageList = os.listdir('static/images')
#imageList = ['images/' + image for image in imageList]
@ -28,24 +16,20 @@ def homepage():
@app.route('/orario')
def orario():
logging.info("A user went up: Orario")
if 'username' in session:
return "You are logged in as " + session['username']
#return render_template('html/orario.html')
@app.route('/calendario')
def calendario():
logging.info("A user went up: Calendario")
return render_template('html/calendario.html')
# Da sistemare
@app.route('/api', methods = ['GET', 'POST'])
def api():
logging.info("A user went up: API")
if(request.method == 'GET'):
data = "hello world"
return jsonify({'data': data})
if __name__ == '__main__':
logging.info("Web server started!")
app.run()

View File

@ -5,115 +5,34 @@ from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
# Libraries for MongoDB and .env file
from pymongo import MongoClient
from dotenv import load_dotenv
import urllib.parse
import pymongo
import time
from pymongo import MongoClient
import urllib.parse
import os
#Load .env file
load_dotenv()
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
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["school-time-table"] #Collection school time table current
# Settings for Firefox
USERNAME = ""
PASSWORD = ""
options = Options()
options.add_argument("--headless") # Headless mode (so you don't see the browser)
options.add_argument('--disable-gpu') # Disable GPU
options.add_argument("--headless")
options.add_argument('--disable-gpu')
options.add_argument('--disable-software-rasterizer')
driver = webdriver.Firefox(options=options) # Open Firefox and set options
driver.get("https://nuvola.madisoft.it/login") # Open Nuvola website
driver = webdriver.Firefox(options=options)
driver.get("https://nuvola.madisoft.it/login") # Open Nuvola website
def recheck():
time.sleep(10)
check_homework()
# Click on the username field and insert the username, then click on the password field and insert the password.
username = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "username")))
password = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "password")))
# Insert username and password
username.click()
username.clear()
username.send_keys(USERNAME)
password.click()
password.clear()
password.send_keys(PASSWORD)
WebDriverWait(driver, 20).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 Vote School
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, "/html/body/div/div/div[1]/nav/div/div/a[6]"))).click() # Click on the Compiti button
def connect_to_nuvola():
try:
username = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "username"))) # Wait for the username input
password = WebDriverWait(driver, 20).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(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
WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/div[1]/nav/div/div/a[6]"))).click() # Click on homework button
except:
print("Error in login")
def check_homework():
next_homework = 0
if next_homework == 10:
print("ao basta")
else:
date = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]"))) # Print the date
print(date.text())
try:
homework_1 = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p")))
print(homework_1.text())
try:
homework_2 = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p")))
print(homework_2.text())
try:
homework_3 = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[3]/div/ul/li/p")))
print(homework_3.text())
try:
homework_4 = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[4]/div/ul/li/p")))
print(homework_4.text())
try:
homework_5 = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div[2]/div/ul/li[5]/div/ul/li/p")))
print(homework_5.text())
except:
print("Homework 5 not found")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]/svg"))).click() # Click on next day button
next_homework += 1
check_homework()
except:
print("Homework 4 not found")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]/svg"))).click() # Click on next day button
next_homework += 1
check_homework()
except:
print("Homework 3 not found")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]/svg"))).click() # Click on next day button
next_homework += 1
check_homework()
except:
print("Homework 2 not found")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]/svg"))).click() # Click on next day button
next_homework += 1
check_homework()
except:
print("No homework")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]/svg"))).click() # Click on next day button
next_homework += 1
check_homework()
#Date
# /html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[1]
# /html/body/div/div/main/div/div[1]/div[1]/div[1]/div[1]/button[1]
#Button for next day
# /html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]/svg
# /html/body/div/div/main/div/div/div[1]/div[1]/div[1]/button[3]/svg
#Compiti
# /html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p
# /html/body/div/div/main/div/div[2]/div/ul/li[2]/div/ul/li/p
# /html/body/div/div/main/div/div[2]/div/ul/li[1]/div/ul/li/p
#Se non ci sono compiti
# /html/body/div/div/main/div/p
print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/p"))).text)

0
src/log/event.log Normal file
View File