mirror of
https://github.com/assenzostefano/class-website.git
synced 2025-02-16 20:00:41 +01:00
Compare commits
No commits in common. "f7ce81ef5d775d943ede3757fdcc6dfa59c2b2b6" and "607d3715348eb94620ea3e1dace2a10721c1a57d" have entirely different histories.
f7ce81ef5d
...
607d371534
15
.env.example
15
.env.example
@ -1,15 +1,8 @@
|
|||||||
# Databse (MongoDB)
|
|
||||||
PASSWORD_MONGODB = ""
|
PASSWORD_MONGODB = ""
|
||||||
URL_MONGODB = ""
|
URL_MONGODB = ""
|
||||||
|
|
||||||
# Email
|
|
||||||
IMAP_SERVER = ""
|
|
||||||
SMTP_PORT = ""
|
|
||||||
EMAIL = ""
|
|
||||||
PWD_EMAIL = ""
|
PWD_EMAIL = ""
|
||||||
|
EMAIL = "
|
||||||
|
SMTP_SERVER = ""
|
||||||
|
SMTP_PORT = ""
|
||||||
EMAIL_SCHOOL = ""
|
EMAIL_SCHOOL = ""
|
||||||
DOWNLOAD_FOLDER = ""
|
DOWNLOAD_FOLDER = ""
|
||||||
|
|
||||||
# Nuvola
|
|
||||||
USERNAME_NUVOLA = ""
|
|
||||||
PASSWORD_NUVOLA = ""
|
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
test.xlsx
|
test.xlsx
|
||||||
.env
|
.env
|
||||||
geckodriver.log
|
geckodriver.log
|
||||||
all.log
|
|
16
app.py
16
app.py
@ -1,26 +1,14 @@
|
|||||||
from flask import Flask, render_template, request, session, jsonify
|
from flask import Flask, render_template, request, session, jsonify
|
||||||
import requests
|
import requests
|
||||||
import logging
|
|
||||||
import bcrypt
|
import bcrypt
|
||||||
import sys
|
|
||||||
import os
|
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__)
|
app = Flask(__name__)
|
||||||
IMAGE_FOLDER = os.path.join('static', 'images')
|
IMAGE_FOLDER = os.path.join('static', 'images')
|
||||||
app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER
|
app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def homepage():
|
def homepage():
|
||||||
logging.info("A user went up: Homepage")
|
|
||||||
return render_template('html/index.html')
|
return render_template('html/index.html')
|
||||||
#imageList = os.listdir('static/images')
|
#imageList = os.listdir('static/images')
|
||||||
#imageList = ['images/' + image for image in imageList]
|
#imageList = ['images/' + image for image in imageList]
|
||||||
@ -28,24 +16,20 @@ def homepage():
|
|||||||
|
|
||||||
@app.route('/orario')
|
@app.route('/orario')
|
||||||
def orario():
|
def orario():
|
||||||
logging.info("A user went up: Orario")
|
|
||||||
if 'username' in session:
|
if 'username' in session:
|
||||||
return "You are logged in as " + session['username']
|
return "You are logged in as " + session['username']
|
||||||
#return render_template('html/orario.html')
|
#return render_template('html/orario.html')
|
||||||
|
|
||||||
@app.route('/calendario')
|
@app.route('/calendario')
|
||||||
def calendario():
|
def calendario():
|
||||||
logging.info("A user went up: Calendario")
|
|
||||||
return render_template('html/calendario.html')
|
return render_template('html/calendario.html')
|
||||||
|
|
||||||
# Da sistemare
|
# Da sistemare
|
||||||
@app.route('/api', methods = ['GET', 'POST'])
|
@app.route('/api', methods = ['GET', 'POST'])
|
||||||
def api():
|
def api():
|
||||||
logging.info("A user went up: API")
|
|
||||||
if(request.method == 'GET'):
|
if(request.method == 'GET'):
|
||||||
data = "hello world"
|
data = "hello world"
|
||||||
return jsonify({'data': data})
|
return jsonify({'data': data})
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.info("Web server started!")
|
|
||||||
app.run()
|
app.run()
|
@ -5,115 +5,34 @@ from selenium.webdriver.firefox.options import Options
|
|||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
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 pymongo
|
||||||
import time
|
from pymongo import MongoClient
|
||||||
|
import urllib.parse
|
||||||
import os
|
import os
|
||||||
|
|
||||||
#Load .env file
|
USERNAME = ""
|
||||||
load_dotenv()
|
PASSWORD = ""
|
||||||
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
|
|
||||||
options = Options()
|
options = Options()
|
||||||
options.add_argument("--headless") # Headless mode (so you don't see the browser)
|
options.add_argument("--headless")
|
||||||
options.add_argument('--disable-gpu') # Disable GPU
|
options.add_argument('--disable-gpu')
|
||||||
|
options.add_argument('--disable-software-rasterizer')
|
||||||
|
|
||||||
driver = webdriver.Firefox(options=options) # Open Firefox and set options
|
driver = webdriver.Firefox(options=options)
|
||||||
driver.get("https://nuvola.madisoft.it/login") # Open Nuvola website
|
driver.get("https://nuvola.madisoft.it/login") # Open Nuvola website
|
||||||
|
|
||||||
def recheck():
|
# Click on the username field and insert the username, then click on the password field and insert the password.
|
||||||
time.sleep(10)
|
username = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "username")))
|
||||||
check_homework()
|
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():
|
print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/main/div/p"))).text)
|
||||||
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
|
|
0
src/log/event.log
Normal file
0
src/log/event.log
Normal file
Loading…
x
Reference in New Issue
Block a user