mirror of
https://github.com/assenzostefano/class-website.git
synced 2025-06-06 00:39:12 +02:00
Now api school time works!
This commit is contained in:
@@ -13,24 +13,17 @@ app = Flask(__name__)
|
|||||||
load_dotenv() #Load .env file
|
load_dotenv() #Load .env file
|
||||||
PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
|
PASSWORD_MONGODB = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
|
||||||
URL_MONGODB = os.getenv('URL_MONGODB') #URL 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"
|
mongo_url = "mongodb+srv://elci:" + urllib.parse.quote_plus(PASSWORD_MONGODB) + URL_MONGODB #URL for MongoDB (with password)
|
||||||
print(mongo_url) #URL for MongoDB (with password)
|
|
||||||
client = MongoClient(mongo_url) #Connect to MongoDB
|
client = MongoClient(mongo_url) #Connect to MongoDB
|
||||||
database = client["website-class"] #Database name
|
database = client["website-class"] #Database name
|
||||||
collection = database["school-time-table"]
|
collection = database["school-time-table"]
|
||||||
db = client.get_database()
|
|
||||||
|
|
||||||
@app.route("/", methods=["GET"])
|
@app.route("/", methods=["GET"])
|
||||||
def get_subjects():
|
def get_subjects():
|
||||||
schedule_collection = db.schedule
|
subjects = collection.find({}, {"_id": 0})
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
|
#Return all subjects
|
||||||
|
return jsonify(list(subjects))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run()
|
app.run()
|
Reference in New Issue
Block a user