67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
from settings.logger import log_function_call, logger
|
|
from utils import sql_insert, sql_select, sql_update
|
|
import time
|
|
from datetime import datetime
|
|
from main_settings import main_settings
|
|
|
|
|
|
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]] = list(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:
|
|
if main_settings.get(2)[2] == 1:
|
|
for obj in self.list:
|
|
if self.list[obj][7] == 0:
|
|
if self.list[obj][2] <= datetime.now():
|
|
print(f"Будильник {self.list[obj][1]}")
|
|
#TODO Сделать отправку уведомленния
|
|
self.switch_timer(obj, 1)
|
|
|
|
time.sleep(1)
|
|
|
|
timers = TIMERS() |