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