#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras #=================================================================== # using flask restful from flask import Flask, request, jsonify from flask_restful import Resource, Api from json import dumps import json from flask_cors import CORS import mysql.connector # ================================================================== # ================================================================== # creating the flask app app = Flask(__name__) CORS(app) # creating an API object api = Api(app) # Initialize the database Connection mydb = mysql.connector.connect( host = "q2gen47hi68k1yrb.chr7pe7iynqr.eu-west-1.rds.amazonaws.com", user = "zsgmj50h7zgz9ioq", password = "omk5l1hrwsgvlcez", database = "g0s9cnmdkziq6fsp" ) myCursor = mydb.cursor() # ================================== # Define our functions. # Define a function that gets the parking status # for all parking codes. def getParkings(): parks = dict() myCursor.execute("SELECT * FROM PARKING") myRes = myCursor.fetchall() for res in myRes: parks[res[0]] = res[1] return parks # ================================================================== # making a class for a particular resource # the get, post methods correspond to get and post requests # they are automatically mapped by flask_restful. # other methods include put, delete, etc. class Parking(Resource): def get(self): parks = getParkings() return parks, 200 class ParkingStatus(Resource): def get(self): return """