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