Added function to remove 'old' services
This commit is contained in:
parent
02f51d9ad2
commit
eb6b7aefb0
17
services.py
17
services.py
@ -51,6 +51,8 @@ class Services:
|
|||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
|
|
||||||
def AddService(self, date, groups):
|
def AddService(self, date, groups):
|
||||||
|
if(date < datetime.datetime.now()):
|
||||||
|
return "You cant add a date in the past"
|
||||||
query = f"""
|
query = f"""
|
||||||
INSERT INTO services (date, groups)
|
INSERT INTO services (date, groups)
|
||||||
VALUES('{date}', '{groups}');
|
VALUES('{date}', '{groups}');
|
||||||
@ -70,6 +72,17 @@ class Services:
|
|||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
|
def CleanServices(self):
|
||||||
|
"""
|
||||||
|
Remove all services that are in the past
|
||||||
|
"""
|
||||||
|
ser = self.GetAllServices()
|
||||||
|
for i in ser:
|
||||||
|
if(ser[i][0] < datetime.datetime.now()):
|
||||||
|
#delete service that lives in the past
|
||||||
|
self.RemoveService(ser[i][0])
|
||||||
|
|
||||||
|
|
||||||
class UserManager():
|
class UserManager():
|
||||||
def __init__(self, db) -> None:
|
def __init__(self, db) -> None:
|
||||||
self.db = db
|
self.db = db
|
||||||
@ -126,9 +139,9 @@ if __name__ == "__main__":
|
|||||||
ser = Services(db)
|
ser = Services(db)
|
||||||
us = UserManager(db)
|
us = UserManager(db)
|
||||||
|
|
||||||
us.AddUser("Eljakim", "Kunnenwe?")
|
# us.AddUser("Eljakim", "Kunnenwe?")
|
||||||
us.Authenticate("Eljakim", "Kunnenwe?")
|
us.Authenticate("Eljakim", "Kunnenwe?")
|
||||||
us.Authenticate("Eljakim", "Kunnenwe2?")
|
ser.CleanServices()
|
||||||
# for i in range(100):
|
# for i in range(100):
|
||||||
# d = datetime.datetime.now()
|
# d = datetime.datetime.now()
|
||||||
# d = d.replace(hour=random.randint(1, 23), day = random.randint(1, 28), month = random.randint(1, 12))
|
# d = d.replace(hour=random.randint(1, 23), day = random.randint(1, 28), month = random.randint(1, 12))
|
||||||
|
Loading…
Reference in New Issue
Block a user