Added function to remove 'old' services

This commit is contained in:
Eljakim Herrewijnen 2021-11-10 22:07:37 +01:00
parent 02f51d9ad2
commit eb6b7aefb0
2 changed files with 15 additions and 2 deletions

View File

@ -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))

BIN
sqlite.db

Binary file not shown.