FMN_bot/src/fmn_states_db.py

34 lines
733 B
Python
Raw Permalink Normal View History

2022-11-21 20:33:00 +00:00
import json
2022-09-06 23:55:12 +00:00
from loguru import logger
2022-08-31 14:46:05 +00:00
2022-11-21 20:33:00 +00:00
states_file = 'fmn_states.json'
2023-07-27 14:22:06 +00:00
class states_stor:
states = None
2022-11-21 20:33:00 +00:00
@logger.catch
def read_states():
try:
with open(states_file, 'rt') as f:
current_states = json.loads(f.read())
except:
logger.warning('Стейты не найдены, создание плейсхолдера')
write_states()
current_states = {}
return current_states
@logger.catch
def write_states(new_states={}):
2022-11-21 20:33:00 +00:00
with open(states_file, 'wt') as f:
f.write(json.dumps(new_states, indent=4))
if new_states == {}:
2022-11-21 20:33:00 +00:00
logger.info('states empty wrote')
return new_states
2022-08-31 15:27:57 +00:00
if not states_stor.states:
states_stor.states = read_states()