From c1ba2cf5b59a756284f66b098225c6920110e29d Mon Sep 17 00:00:00 2001 From: Stefano Assenzo Date: Fri, 13 Jan 2023 15:50:30 +0000 Subject: [PATCH] Create API for homework --- subdomains/api/homework/app.py | 23 +++++++++++++++++++++++ subdomains/api/{ => school_time}/app.py | 0 2 files changed, 23 insertions(+) create mode 100644 subdomains/api/homework/app.py rename subdomains/api/{ => school_time}/app.py (100%) diff --git a/subdomains/api/homework/app.py b/subdomains/api/homework/app.py new file mode 100644 index 0000000..71c33b0 --- /dev/null +++ b/subdomains/api/homework/app.py @@ -0,0 +1,23 @@ +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() \ No newline at end of file diff --git a/subdomains/api/app.py b/subdomains/api/school_time/app.py similarity index 100% rename from subdomains/api/app.py rename to subdomains/api/school_time/app.py