FMN_bot/src/fmn_states_db.py

26 lines
610 B
Python

import json
from loguru import logger
states_file = 'fmn_states.json'
@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(states={}):
with open(states_file, 'wt') as f:
f.write(json.dumps(states, indent=4))
if states == {}:
logger.info('states empty wrote')
return states