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]] = list(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 def get(self, id): return self.list[id] 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!')