123
This commit is contained in:
parent
651c16558c
commit
7f9723d9f4
|
|
@ -41,6 +41,5 @@ class MAIN_FUNC:
|
|||
print(e)
|
||||
return False
|
||||
|
||||
logger.info('START | 3/4 | Load main_func')
|
||||
main_func = MAIN_FUNC()
|
||||
logger.info('START | 4/4 | Success!')
|
||||
logger.info('START | 3/5 | Load main_func')
|
||||
main_func = MAIN_FUNC()
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
from settings.logger import log_function_call, logger
|
||||
from utils import sql_insert, sql_select, sql_update
|
||||
|
||||
|
||||
class MAIN_SETTINGS:
|
||||
def __init__(self):
|
||||
self.self = self
|
||||
self.list = {}
|
||||
|
||||
@log_function_call
|
||||
def load_settings(self):
|
||||
t = 'SELECT * FROM main_settings'
|
||||
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 edit_setting(self, id, value):
|
||||
if self.list[id] is None:
|
||||
return False
|
||||
if self.list[id][2] == value:
|
||||
return True
|
||||
try:
|
||||
s = "UPDATE main_settings SET value = %s WHERE id = %s"
|
||||
t = (value, id)
|
||||
m = sql_update(s, t)
|
||||
if m is True:
|
||||
self.list[id][2] = 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
|
||||
|
||||
logger.info('START | 4/5 | Load main_settings')
|
||||
main_settings = MAIN_SETTINGS()
|
||||
logger.info('START | 5/5 | Success!')
|
||||
53
start.py
53
start.py
|
|
@ -1,23 +1,38 @@
|
|||
from utils import *
|
||||
from main_func import main_func
|
||||
from main_settings import main_settings
|
||||
from timers import timers
|
||||
import time
|
||||
|
||||
data = {
|
||||
'page': 'testing',
|
||||
'site': 'test_work',
|
||||
'data': (1, 23, 'vok1no', (1, 2, 3))
|
||||
}
|
||||
r = main_func.create_log(data)
|
||||
d = main_func.get_settings()
|
||||
print(d)
|
||||
print(r)
|
||||
c = main_func.get_setting('debug_log_type')
|
||||
print(c)
|
||||
if c == 1:
|
||||
logger.info(f'DEBUG_LOG_TYPE -> {c} | Включение режима!')
|
||||
interval = 2 # интервал в секундах
|
||||
while True:
|
||||
print(f"DEBUG_LOG: Сейчас {time.ctime()}")
|
||||
time.sleep(2)
|
||||
else:
|
||||
logger.info(f'DEBUG_LOG_TYPE -> {c} | Без включения!')
|
||||
|
||||
timers.load_timers()
|
||||
timers.activate_check()
|
||||
|
||||
|
||||
|
||||
|
||||
# main_settings.load_settings()
|
||||
# print(main_settings.list[1][1])
|
||||
# print(main_settings.edit_setting(2, 0))
|
||||
# m = main_settings.get_by_name('active')
|
||||
# print(m)
|
||||
|
||||
# data = {
|
||||
# 'page': 'testing',
|
||||
# 'site': 'test_work',
|
||||
# 'data': (1, 23, 'vok1no', (1, 2, 3))
|
||||
# }
|
||||
# r = main_func.create_log(data)
|
||||
# d = main_func.get_settings()
|
||||
# print(d)
|
||||
# print(r)
|
||||
# c = main_func.get_setting('debug_log_type')
|
||||
# print(c)
|
||||
# if c == 1:
|
||||
# logger.info(f'DEBUG_LOG_TYPE -> {c} | Включение режима!')
|
||||
# interval = 2 # интервал в секундах
|
||||
# while True:
|
||||
# print(f"DEBUG_LOG: Сейчас {time.ctime()}")
|
||||
# time.sleep(2)
|
||||
# else:
|
||||
# logger.info(f'DEBUG_LOG_TYPE -> {c} | Без включения!')
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
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()
|
||||
6
utils.py
6
utils.py
|
|
@ -4,12 +4,12 @@ import mysql.connector
|
|||
import json
|
||||
from settings.logger import log_function_call, logger
|
||||
|
||||
logger.info('START | 0/4 | Load dotenv')
|
||||
logger.info('START | 0/5 | Load dotenv')
|
||||
|
||||
load_dotenv()
|
||||
|
||||
try:
|
||||
logger.info('START | 1/4 | Load DB')
|
||||
logger.info('START | 1/5 | Load DB')
|
||||
mydb = mysql.connector.connect(
|
||||
host=os.getenv('DB_HOST'),
|
||||
user=os.getenv('DB_USER'),
|
||||
|
|
@ -20,7 +20,7 @@ except mysql.connector.Error as e:
|
|||
print(f"Ошибка при подключении к БД: {e}")
|
||||
mydb = None
|
||||
|
||||
logger.info('START | 2/4 | Load sql functions')
|
||||
logger.info('START | 2/5 | Load sql functions')
|
||||
@log_function_call
|
||||
def update_sql_connect():
|
||||
global mydb # Указываем, что используем глобальную переменную
|
||||
|
|
|
|||
Loading…
Reference in New Issue