some changing
This commit is contained in:
38
test.py
38
test.py
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user