I am doing too many things
This commit is contained in:
parent
4f4458c425
commit
566d3e2811
12
app.py
12
app.py
|
@ -1,12 +1,9 @@
|
|||
from urllib.request import Request, urlopen
|
||||
from flask import Flask, render_template, url_for, request, redirect, session, flash, jsonify
|
||||
from flask_pymongo import PyMongo
|
||||
from dotenv import load_dotenv
|
||||
import bcrypt
|
||||
import urllib
|
||||
from flask import Flask, render_template, url_for, request, redirect, session
|
||||
from pymongo import MongoClient
|
||||
from dotenv import load_dotenv
|
||||
import logging
|
||||
import json
|
||||
import urllib
|
||||
import bcrypt
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
@ -55,7 +52,6 @@ def MongoDB():
|
|||
|
||||
records = MongoDB()
|
||||
|
||||
|
||||
#assign URLs to have a particular route
|
||||
@app.route("/register", methods=['post', 'get'])
|
||||
def register():
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
from bson.objectid import ObjectId
|
||||
from dotenv import load_dotenv
|
||||
from telebot import telebot
|
||||
import datetime
|
||||
import schedule
|
||||
import pymongo
|
||||
import urllib
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
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["subscribe"] #Collection school time table current
|
||||
collection_schooltime = database["school-time-table"] #Collection school time table current
|
||||
API_TOKEN = os.getenv('TELEGRAM_TOKEN')
|
||||
bot = telebot.TeleBot(API_TOKEN)
|
||||
|
||||
@bot.message_handler(commands=['start'])
|
||||
def send_welcome(message):
|
||||
bot.send_message(message.chat.id, "Hello, I'm a bot")
|
||||
|
||||
@bot.message_handler(commands=['subscribe'])
|
||||
def subscribe(message):
|
||||
take_id = message.from_user.id #Get user id
|
||||
#Insert the id of the user who writes /subscribe in the database
|
||||
find_document_username = list(collection.find({}, {"_id": 1}))
|
||||
array_username = find_document_username[0]["_id"]
|
||||
collection.update_one(
|
||||
{ "_id": ObjectId(array_username)},
|
||||
{
|
||||
"$push": { "username": take_id }
|
||||
}
|
||||
)
|
||||
bot.send_message(message.chat.id, "You are subscribed")
|
||||
|
||||
def send_notification():
|
||||
# Inserisci il giorno di oggi
|
||||
today = datetime.datetime.today().strftime('%A')
|
||||
# Print hours
|
||||
now = datetime.datetime.now()
|
||||
print(now.strftime("%H:%M"))
|
||||
finish = False
|
||||
while finish == False:
|
||||
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
|
||||
find_document = list(collection_schooltime.find({}, {"_id": 0, "School Subject": 1}))
|
||||
#gaga = find_document['School Subject'][today][0]['Subject']
|
||||
if now.strftime("%H:%M") == "07:50":
|
||||
for i in find_document:
|
||||
print(i['School Subject'][today][0]['Subject'])
|
||||
elif now.strftime("%H:%M") == "08:53":
|
||||
for i in find_document:
|
||||
print(i['School Subject'][today][1]['Subject'])
|
||||
elif now.strftime("%H:%M") == "09:53":
|
||||
for i in find_document:
|
||||
print(i['School Subject'][today][2]['Subject'])
|
||||
elif now.strftime("%H:%M") == "10:53":
|
||||
for i in find_document:
|
||||
print(i['School Subject'][today][3]['Subject'])
|
||||
elif now.strftime("%H:%M") == "12:08":
|
||||
for i in find_document:
|
||||
print(i['School Subject'][today][4]['Subject'])
|
||||
elif now.strftime("%H:%M") == "13:08":
|
||||
for i in find_document:
|
||||
print(i['School Subject'][today][5]['Subject'])
|
||||
finish == True
|
||||
else:
|
||||
pass
|
||||
|
||||
while True:
|
||||
schedule.every().day.at("07:50").do(send_notification)
|
||||
bot.polling()
|
|
@ -11,6 +11,7 @@ from selenium import webdriver
|
|||
# Libraries for MongoDB and .env file
|
||||
from dotenv import load_dotenv
|
||||
import urllib.parse
|
||||
import datetime
|
||||
import pymongo
|
||||
import time
|
||||
import os
|
||||
|
@ -32,7 +33,7 @@ options.add_argument("--headless") # Headless mode (so you don't see the browser
|
|||
options.add_argument('--disable-gpu') # Disable GPU
|
||||
|
||||
def start_search():
|
||||
time.sleep(7200)
|
||||
#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
|
||||
|
@ -49,12 +50,13 @@ def start_search():
|
|||
|
||||
# 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()
|
||||
|
||||
def homework_check():
|
||||
day_one.giorno_uno(driver, collection)
|
||||
driver.close()
|
||||
start_search()
|
||||
print("Finish")
|
||||
start_search()
|
||||
|
||||
start_search()
|
|
@ -6,303 +6,53 @@ 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
|
||||
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
|
||||
# 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:
|
||||
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
|
||||
# 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:
|
||||
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_two.giorno_due(driver, collection)
|
||||
# No more days to scrape, end function
|
||||
pass
|
||||
|
||||
except:
|
||||
print("Error")
|
||||
|
|
|
@ -69,6 +69,6 @@ def check_email():
|
|||
def send_xlsx():
|
||||
from update_time_school import update_time_school
|
||||
update_time_school()
|
||||
os.remove(f"{DOWNLOAD_FOLDER}/school_time.xlsx") # Delete file
|
||||
#os.remove(f"{DOWNLOAD_FOLDER}/school_time.xlsx") # Delete file
|
||||
recheck_email()
|
||||
check_email()
|
|
@ -1,11 +1,10 @@
|
|||
from bson.objectid import ObjectId
|
||||
from openpyxl.styles import NamedStyle
|
||||
from bson.objectid import ObjectId
|
||||
from dotenv import load_dotenv
|
||||
import openpyxl as xl
|
||||
import datetime
|
||||
import pymongo
|
||||
import urllib
|
||||
import datetime
|
||||
import os
|
||||
|
||||
load_dotenv() #Load .env file
|
||||
|
@ -450,12 +449,9 @@ def update_time_school():
|
|||
number_teacher = 1
|
||||
number_room = 1
|
||||
number = 1
|
||||
current_day = None
|
||||
day_counter = 0
|
||||
number_day = 0
|
||||
#Search my class in excel file and add in MongoDB
|
||||
number = 1
|
||||
gagaga = 0
|
||||
#Search my class in excel file and add in MongoDB
|
||||
for row in range (1, 100):
|
||||
# column B ~ column F
|
||||
for column in range (1, 100):
|
||||
|
@ -465,15 +461,17 @@ def update_time_school():
|
|||
for i in range(4,80):
|
||||
day = str(ws.cell(row=i, column=3).value) # Get day from excel file
|
||||
school_subject = ws.cell(row=i, column=column).value # Get school subject from excel file
|
||||
teacher = ws.cell(row=i, column=column+1).value
|
||||
room = ws.cell(row=i, column=column+2).value
|
||||
teacher = ws.cell(row=i, column=column+1).value # Get teacher from excel file
|
||||
room = ws.cell(row=i, column=column+2).value # Get room from excel file
|
||||
|
||||
# Simple counter for don't repeat
|
||||
if dont_repeat == 9:
|
||||
check_repeat += 1
|
||||
if check_repeat == 5:
|
||||
check_repeat = 0
|
||||
dont_repeat = 0
|
||||
else:
|
||||
if day == "None":
|
||||
if day == "None": #If day is None, don't add a school subject in MongoDB
|
||||
if school_subject == 0 or school_subject == "0": #If school subject is 0, add "" in MongoDB
|
||||
number += 1
|
||||
gagaga += 1
|
||||
|
@ -488,6 +486,8 @@ def update_time_school():
|
|||
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||
|
||||
# Shorten school subject name
|
||||
if remove_things_in_front == "MISURE ELETTRICHE":
|
||||
remove_things_in_front = "MISURE"
|
||||
elif remove_things_in_front == " EDUCAZIONE ATTIVITA' MOTORIE":
|
||||
|
@ -504,16 +504,17 @@ def update_time_school():
|
|||
remove_things_in_front = "INGLESE"
|
||||
elif remove_things_in_front == "SCIENZE INTEGRATE - FISICA":
|
||||
remove_things_in_front = "FISICA"
|
||||
elif remove_things_in_front == "21PM2 LABORATORIO ELETTRICO":
|
||||
remove_things_in_front == "LAB. ELETTRICO"
|
||||
|
||||
# Add school subject in MongoDB beacause school subject is not 0
|
||||
collection.update_one(
|
||||
collection.update_one( # Add school subject in MongoDB beacause school subject is not 0
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": remove_things_in_front,
|
||||
}
|
||||
}
|
||||
)
|
||||
collection_archive.update_one(
|
||||
collection_archive.update_one( # Add school subject in MongoDB (archive) beacause school subject is not 0
|
||||
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": remove_things_in_front,
|
||||
|
@ -523,29 +524,30 @@ def update_time_school():
|
|||
number += 1
|
||||
gagaga += 1
|
||||
dont_repeat += 1
|
||||
# Simple counter for don't repeat
|
||||
if number == 9:
|
||||
number = 1
|
||||
if gagaga == 8:
|
||||
gagaga = 0
|
||||
else:
|
||||
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
|
||||
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
|
||||
array_test = []
|
||||
array_test.append(convert_date_to_day)
|
||||
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y") # Convert date to day
|
||||
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A') # Convert date to day
|
||||
array_test = [] # Create array
|
||||
array_test.append(convert_date_to_day) # Add day in array
|
||||
number_day += 1
|
||||
if school_subject == 0 or school_subject == "0": #If school subject is 0, add "" in MongoDB
|
||||
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||
collection.update_one(
|
||||
collection.update_one( # Add "" in MongoDB beacause school subject is 0
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
|
||||
}
|
||||
}
|
||||
)
|
||||
collection_archive.update_one(
|
||||
collection_archive.update_one( # Add "" in MongoDB (archive) beacause school subject is 0
|
||||
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
|
||||
|
@ -562,42 +564,39 @@ def update_time_school():
|
|||
if gagaga == 8:
|
||||
gagaga = 0
|
||||
else: #If school subject is not 0, add school subject in MongoDB
|
||||
if school_subject == "21PM1 MISURE ELETTRICHE":
|
||||
if school_subject == "MISURE ELETTRICHE":
|
||||
school_subject = "MISURE"
|
||||
elif school_subject == " CEAM EDUCAZIONE ATTIVITA' MOTORIE":
|
||||
elif school_subject == " EDUCAZIONE ATTIVITA' MOTORIE":
|
||||
school_subject = "MOTORIA"
|
||||
elif school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE":
|
||||
school_subject = "MOTORIA"
|
||||
elif school_subject == "CSGGE1 DIRITTO ED ECONOMIA":
|
||||
elif school_subject == "EDUCAZIONE ATTIVITA' MOTORIE":
|
||||
school_subject = "Motoria"
|
||||
elif school_subject == "DIRITTO ED ECONOMIA":
|
||||
school_subject = "DIRITTO"
|
||||
elif school_subject == "PR1 INGLESE PROFESSIONALE":
|
||||
elif school_subject == "INGLESE PROFESSIONALE":
|
||||
school_subject = "INGLESE PRO."
|
||||
elif school_subject == "PR1 LABORATORIO ELETTRICO":
|
||||
elif school_subject == "LABORATORIO ELETTRICO":
|
||||
school_subject = "LAB. ELETTRICO"
|
||||
elif school_subject == "CLING LINGUA INGLESE":
|
||||
elif school_subject == "LINGUA INGLESE":
|
||||
school_subject = "INGLESE"
|
||||
elif school_subject == "CMST2 SCIENZE INTEGRATE - FISICA":
|
||||
elif school_subject == "SCIENZE INTEGRATE - FISICA":
|
||||
school_subject = "FISICA"
|
||||
elif school_subject == "PR1 DISEGNO":
|
||||
school_subject = "DISEGNO"
|
||||
elif school_subject == "CSGGE2 STORIA":
|
||||
school_subject = "STORIA"
|
||||
elif school_subject == "CMST1 MATEMATICA":
|
||||
school_subject = "MATEMATICA"
|
||||
elif school_subject == "21PM2 LABORATORIO ELETTRICO":
|
||||
school_subject == "LAB. ELETTRICO"
|
||||
|
||||
# Search document on MongoDB
|
||||
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||
# Add school subject in MongoDB beacause school subject is not 0
|
||||
collection.update_one(
|
||||
|
||||
collection.update_one( # Add school subject in MongoDB beacause school subject is not 0
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
|
||||
}
|
||||
}
|
||||
)
|
||||
collection_archive.update_one(
|
||||
collection_archive.update_one( # Add school subject in MongoDB (archive) beacause school subject is not 0
|
||||
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
|
||||
|
@ -607,6 +606,7 @@ def update_time_school():
|
|||
number += 1
|
||||
gagaga += 1
|
||||
dont_repeat += 1
|
||||
# Simple counter for don't repeat
|
||||
if number == 9:
|
||||
number = 1
|
||||
if gagaga == 8:
|
||||
|
@ -618,10 +618,10 @@ def update_time_school():
|
|||
if check_repeat_teacher == 5:
|
||||
check_repeat_teacher = 0
|
||||
dont_repeat_teacher = 0
|
||||
#number = 1
|
||||
else:
|
||||
if day == "None":
|
||||
if teacher == 0:
|
||||
if day == "None": # Check if day is None
|
||||
if teacher == 0: # Check if teacher is 0
|
||||
# If teacher is 0, add anything in MongoDB
|
||||
number_teacher += 1
|
||||
gagaga_teacher += 1
|
||||
dont_repeat_teacher += 1
|
||||
|
@ -630,18 +630,20 @@ def update_time_school():
|
|||
if gagaga_teacher == 9:
|
||||
gagaga_teacher = 0
|
||||
else:
|
||||
# Search document on MongoDB
|
||||
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||
collection.update_one(
|
||||
|
||||
collection.update_one( # Add teacher in MongoDB beacause teacher is not 0
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_teacher) + ".Teacher": teacher,
|
||||
}
|
||||
}
|
||||
)
|
||||
collection_archive.update_one(
|
||||
collection_archive.update_one( # Add teacher in MongoDB (archive) beacause teacher is not 0
|
||||
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_teacher)+ ".Teacher": teacher,
|
||||
|
@ -656,22 +658,25 @@ def update_time_school():
|
|||
if gagaga_teacher == 8:
|
||||
gagaga_teacher = 0
|
||||
else:
|
||||
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
|
||||
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
|
||||
array_test = []
|
||||
array_test.append(convert_date_to_day)
|
||||
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y") # Convert date to day
|
||||
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A') # Convert date to day
|
||||
array_test = [] # Create array
|
||||
array_test.append(convert_date_to_day) # Add day in array
|
||||
|
||||
# Search document on MongoDB
|
||||
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||
collection.update_one(
|
||||
|
||||
collection.update_one( # Add teacher in MongoDB beacause teacher is not 0
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_teacher)+ ".Teacher": teacher,
|
||||
}
|
||||
}
|
||||
)
|
||||
collection_archive.update_one(
|
||||
collection_archive.update_one( # Add teacher in MongoDB (archive) beacause teacher is not 0
|
||||
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_teacher)+ ".Teacher": teacher,
|
||||
|
@ -681,6 +686,7 @@ def update_time_school():
|
|||
number_teacher += 1
|
||||
gagaga_teacher += 1
|
||||
dont_repeat_teacher += 1
|
||||
# Simple counter for don't repeat
|
||||
if number_teacher == 9:
|
||||
number_teacher = 1
|
||||
if gagaga_teacher == 8:
|
||||
|
@ -693,7 +699,7 @@ def update_time_school():
|
|||
check_repeat_room = 0
|
||||
dont_repeat_room = 0
|
||||
else:
|
||||
if day == "None":
|
||||
if day == "None": # Check if day is None
|
||||
if room == 0:
|
||||
number_room += 1
|
||||
gagaga_room += 1
|
||||
|
@ -703,18 +709,20 @@ def update_time_school():
|
|||
if gagaga_room == 9:
|
||||
gagaga_room = 0
|
||||
else:
|
||||
# Search document on MongoDB
|
||||
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||
collection.update_one(
|
||||
|
||||
collection.update_one( # Add room in MongoDB beacause room is not 0
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_room) + ".Room": room,
|
||||
}
|
||||
}
|
||||
)
|
||||
collection_archive.update_one(
|
||||
collection_archive.update_one( # Add room in MongoDB (archive) beacause room is not 0
|
||||
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_room)+ ".Room": room,
|
||||
|
@ -724,27 +732,32 @@ def update_time_school():
|
|||
number_room += 1
|
||||
gagaga_room += 1
|
||||
dont_repeat_room += 1
|
||||
|
||||
# Simple counter for don't repeat
|
||||
if number_room == 9:
|
||||
number_room = 1
|
||||
if gagaga_room == 8:
|
||||
gagaga_room = 0
|
||||
else:
|
||||
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
|
||||
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y") # Convert date to day
|
||||
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
|
||||
array_test = []
|
||||
array_test.append(convert_date_to_day)
|
||||
array_test = [] # Create array
|
||||
array_test.append(convert_date_to_day) # Add day in array
|
||||
|
||||
# Search document on MongoDB
|
||||
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||
collection.update_one(
|
||||
|
||||
collection.update_one( # Add room in MongoDB beacause room is not 0
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_room)+ ".Room": room,
|
||||
}
|
||||
}
|
||||
)
|
||||
collection_archive.update_one(
|
||||
collection_archive.update_one( # Add room in MongoDB (archive) beacause room is not 0
|
||||
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_room)+ ".Room": room,
|
||||
|
@ -754,6 +767,8 @@ def update_time_school():
|
|||
number_room += 1
|
||||
gagaga_room += 1
|
||||
dont_repeat_room += 1
|
||||
|
||||
# Simple counter for don't repeat
|
||||
if number_room == 9:
|
||||
number_room = 1
|
||||
if gagaga_room == 8:
|
||||
|
@ -763,14 +778,12 @@ def update_time_school():
|
|||
if school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or school_subject == "CEAM EDUCAZIONE ATTIVITA' MOTORIA":
|
||||
for c in range(1,100):
|
||||
search_motoria = ws.cell(row=i, column=c).value
|
||||
#print(search_motoria)
|
||||
if search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIE" or search_motoria == "CEAM EDUCAZIONE ATTIVITA' MOTORIA":
|
||||
if c == column:
|
||||
pass
|
||||
else:
|
||||
search_class = ws.cell(row=3, column=c).value
|
||||
print(search_class)
|
||||
collection.update_one(
|
||||
search_class = ws.cell(row=3, column=c).value # Search class
|
||||
collection.update_one( # Add class in MongoDB
|
||||
{ "_id": ObjectId(array_document_school_time_table)},
|
||||
{ "$set": {
|
||||
"School Subject." + array_test[0] + "." + str(gagaga_room-1)+ ".PE with": search_class,
|
||||
|
|
Loading…
Reference in New Issue