Compare commits

...

2 Commits

Author SHA1 Message Date
Stefano Assenzo cfb9c229f9 Create requirements.txt (empty) 2023-01-13 16:16:57 +00:00
Stefano Assenzo c1ba2cf5b5 Create API for homework 2023-01-13 15:50:30 +00:00
3 changed files with 33 additions and 0 deletions

0
requirements.txt Normal file
View File

View File

@ -0,0 +1,33 @@
from flask import Flask, jsonify
from dotenv import load_dotenv
import urllib.parse
import pymongo
import os
load_dotenv() #Load .env file
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
app = Flask(__name__)
@app.route('/homework')
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"
#}