Now api school time works!

This commit is contained in:
Stefano Assenzo 2023-01-25 17:17:17 +00:00 committed by GitHub
parent 54175f01cd
commit 5c4b983e0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 11 deletions

View File

@ -13,24 +13,17 @@ app = Flask(__name__)
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:gWB3EL%25W%405%5EA%40PGvvYRt@stefano-cluster.iphin.mongodb.net/website-class"
print(mongo_url) #URL for MongoDB (with password)
mongo_url = "mongodb+srv://elci:" + urllib.parse.quote_plus(PASSWORD_MONGODB) + URL_MONGODB #URL for MongoDB (with password)
client = MongoClient(mongo_url) #Connect to MongoDB
database = client["website-class"] #Database name
collection = database["school-time-table"]
db = client.get_database()
@app.route("/", methods=["GET"])
def get_subjects():
schedule_collection = db.schedule
# Utilizza il metodo find() per recuperare tutti i documenti della collezione
# e li converte in una lista
schedule = list(schedule_collection.find())
# Restituisce la risposta come una stringa JSON
return jsonify(schedule)
subjects = collection.find({}, {"_id": 0})
#Return all subjects
return jsonify(list(subjects))
if __name__ == '__main__':
app.run()