diff --git a/src/events/homework/check_homework.py b/src/events/homework/check_homework.py index e702a55..9097e35 100644 --- a/src/events/homework/check_homework.py +++ b/src/events/homework/check_homework.py @@ -9,6 +9,7 @@ from selenium import webdriver # Libraries for MongoDB and .env file from dotenv import load_dotenv import urllib.parse +import datetime import pymongo import os @@ -32,14 +33,28 @@ def giorno_cinque(): #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 = { - "Date": date, - "School Subject": "No school subject", - "Description": description, - } + mydict = { + "subjects": [ + { + "name": "No school subject", + "homework": [ + { + "date": { + "day": split_date[0], + "month": split_date[1], + "year": split_date[2], + }, + "description": description, + } + ] + } + ] + }, + + x = collection.insert_many(mydict) # Insert data in MongoDB - x = collection.insert_one(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": {"School Subject": school_subject}} # Update school subject collection.update_one(mydict, new_school_subject) # Update school subject diff --git a/src/events/homework/test.py b/src/events/homework/test.py new file mode 100644 index 0000000..d74f74c --- /dev/null +++ b/src/events/homework/test.py @@ -0,0 +1,58 @@ +# Libraries for MongoDB and .env file +from dotenv import load_dotenv +import urllib.parse +import pymongo +import os +import datetime + +#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["homework"] #Collection school time table current + +mydict = { + "subjects": [ + { + "name": "Stefanologia", + "homework": [ + { + "date": { + "day": str(12), + "month": str(1), + "year": str(2023), + }, + "description": "Niente compiti yeeee", + } + ] + } + ] +}, +string = "11 january 2023" +a = string.split() +b = a[0] +print(b) +#x = collection.insert_many(mydict) # Insert data in MongoDB + +# { +# "subjects": [ +# { +# "name": "Disegno", +# "homework": [ +# { +# "date": { +# "day": 12, +# "month": 1, +# "year": 2023 +# }, +# "description": "Per le vacanze di natale..." +# } +# ] +# } +# ] +#} \ No newline at end of file diff --git a/subdomains/api/homework/app.py b/subdomains/api/homework/app.py index ce7e8f7..6e901c8 100644 --- a/subdomains/api/homework/app.py +++ b/subdomains/api/homework/app.py @@ -18,16 +18,5 @@ app = Flask(__name__) def get_homework(): homework = collection.find({}, {"_id": 0}) return jsonify(list(homework)) - if __name__ == '__main__': - app.run() - -#{ -# "date": { -# "day": 12, -# "month": 1, -# "year": 2023 -# }, -# "description": "Per le vacanze di natale...", -# "subject": "Disegno" -#} \ No newline at end of file + app.run() \ No newline at end of file