from settings.logger import log_function_call, logger from utils import sql_insert, sql_select, sql_update import time class TIMERS: def __init__(self): self.self = self self.list = {} @log_function_call def load_timers(self): t = 'SELECT * FROM timers' try: res = sql_select(t) self.list = {} for i in res: self.list[i[0]] = i print(i) return 'ok' except SystemError as e: print(e) return False @log_function_call def switch_timer(self, id, value): if self.list[id] is None: return False if self.list[id][7] == value: return True try: s = "UPDATE timers SET is_shutdown = %s WHERE id = %s" t = (value, id) m = sql_update(s, t) if m is True: self.list[id][7] = value return True except SystemError as e: print(e) return False @log_function_call def get(self, id): return self.list[id] @log_function_call def get_by_name(self, name): for obj in self.list: if self.list[obj][1] == name: return self.list[obj] return None def activate_check(self): while True: for obj in self.list: if self.list[obj][7] == 0: # if self.list[obj][2] <= time.time() print(self.list[obj][2]) time.sleep(1) timers = TIMERS()