FMN_bot/src/fmn_states_db.py

26 lines
610 B
Python
Raw Normal View History

2022-11-21 21:33:00 +01:00
import json
2022-09-07 01:55:12 +02:00
from loguru import logger
2022-08-31 16:46:05 +02:00
2022-11-21 21:33:00 +01:00
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
2022-08-31 17:27:57 +02:00