diff --git a/serverNode/__pycache__/serv.cpython-37.pyc b/serverNode/__pycache__/serv.cpython-37.pyc index 04c4797..4585a46 100644 Binary files a/serverNode/__pycache__/serv.cpython-37.pyc and b/serverNode/__pycache__/serv.cpython-37.pyc differ diff --git a/serverNode/serv.py b/serverNode/serv.py index 93230b7..021da9a 100644 --- a/serverNode/serv.py +++ b/serverNode/serv.py @@ -23,15 +23,26 @@ sessions = [] # creating an API object api = Api(app) -# Initialize the database Connection -mydb = mysql.connector.connect( - host = "127.0.0.1",#"q2gen47hi68k1yrb.chr7pe7iynqr.eu-west-1.rds.amazonaws.com", - user = "root",#"zsgmj50h7zgz9ioq", - password = "rootP",#"omk5l1hrwsgvlcez", - database = "PARKING"#"g0s9cnmdkziq6fsp" -) -myCursor = mydb.cursor() +# Initialize the database Connection (Classified) +class mySqlConnect: + def __init__(self): + self.con = con = mysql.connector.connect( + host = "127.0.0.1",#"q2gen47hi68k1yrb.chr7pe7iynqr.eu-west-1.rds.amazonaws.com", + user = "root",#"zsgmj50h7zgz9ioq", + password = "rootP",#"omk5l1hrwsgvlcez", + database = "PARKING"#"g0s9cnmdkziq6fsp" + ) + + self.cur = self.con.cursor(); + + def __del__(self): + self.cur.close() + self.con.close() + + @property + def cursor(self): + return self.cur # ================================== # Define our functions. @@ -40,6 +51,8 @@ myCursor = mydb.cursor() def getParkings(): parks = [] + sql = mySqlConnect() + myCursor = sql.cur myCursor.execute("SELECT * FROM PARKING") myRes = myCursor.fetchall() @@ -53,6 +66,9 @@ def getParkings(): # Define a function that get if a user with exiting credencials # username and password is authenticated. def isMember(username, password): + mysql = mySqlConnect() + myCursor = mysql.cur + myCursor.execute("SELECT * FROM USERS") myRes = myCursor.fetchall() @@ -75,7 +91,6 @@ def isAuthenticated(data): except KeyError as e: return False - # ================================================================== # making a class for a particular resource # the get, post methods correspond to get and post requests @@ -131,6 +146,8 @@ class ParkingStatus(Resource): thereIs = False toUpdate = False + mysql = mySqlConnect() + myCursor = mysql.cur try: if not thereIs: # Make a new insert entry for a new Parking Code.