some changing

This commit is contained in:
2022-06-29 23:17:16 +03:00
parent 25c76bd550
commit 2f9e202adc
4 changed files with 68 additions and 53 deletions

38
test.py
View File

@@ -167,30 +167,24 @@ class Commands:
@staticmethod
async def write_json(guild: int, param_name: str, param: str or int):
with open('prefix.json', 'r', encoding='utf-8') as _f:
_jsonObject = json.load(_f)
with open('prefix.json', 'r') as _f:
try:
_guild_conf = _jsonObject[f"{guild}"]
except KeyError:
_guild_conf = {}
try:
_param = _guild_conf[f"{param_name}"]
except KeyError:
_param = {}
print(f'json is {_jsonObject}\n type {type(_jsonObject)}'
f' Guild is {guild}\n type {type(_param)}'
f' Param name is {param_name}\n type {type(_param)}'
f' param is {param} type {type(_param)}')
_new_param = {f"{param_name}": f'{param}'}
_new_guild = {f"{guild}": {}}
_jsonObject.update(_new_guild)
_guild_conf = _jsonObject[f"{guild}"]
print(f"Guild conf is: {_guild_conf}")
_param.update(_new_param)
print(f"Param is: {_param}")
_guild_conf.update(_param)
_jsonObject = json.load(_f)
except json.JSONDecodeError:
_jsonObject = {}
try:
_guild_conf = _jsonObject[f'{guild}']
except KeyError as error:
_guild_conf = {f'{guild}': {}}
try:
_param = _guild_conf[f"{param_name}"]
with open("prefix.json", "w") as _f:
except KeyError:
_param = {f'{param_name}': f'{param}'}
_jsonObject.update(_guild_conf)
print(_jsonObject)
with open('prefix.json', 'w') as _f:
json.dump(_jsonObject, _f)
_f.close()