Files
audio_resive/functions/file_data.py
T
2023-11-11 09:47:34 +07:00

29 lines
861 B
Python
Executable File

import json
def load_data():
try:
with open('users.json', 'r') as f:
return json.load(f)
except FileNotFoundError:
return {'users': [], 'chats': []}
def save_data(data_type, data_id=None):
data = load_data()
if data_id is None:
if 'static' not in data:
data['static'] = {'audio_resive': 0, 'chatGPT': 0}
if 'audio_resive' not in data['static']:
data['static'][data_type] = 0
if 'chatGPT' not in data['static']:
data['static']['chatGPT'] = 0
data['static'][data_type] += 1
with open('users.json', 'w') as f:
json.dump(data, f, indent=4)
else:
if data_id not in data[data_type]:
data[data_type].append(data_id)
with open('users.json', 'w') as f:
json.dump(data, f, indent=4)