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

34
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 = {}
_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}"]
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)
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()

View File

@@ -2,37 +2,16 @@ import json
def write_json(guild: int, param_name: str, param: str or int):
with open('prefix.json', 'r+', encoding='utf-8') as _f:
with open('prefix.json', 'r', 'utf-8') as _f:
try:
_jsonObject = json.load(_f)
_json = json.load(_f)
except json.decoder.JSONDecodeError:
_jsonObject = {}
_json = {}
_json.update({f'{guild}': {}})
print(_json)
_guild = _json[f'{guild}']
print(_guild)
_guild.update({f'{param_name}': f'{param}'})
print(_json)
try:
_guild_conf = _jsonObject[f"{guild}"]
except KeyError:
_guild_conf = {f"{guild}": {}}
print(_jsonObject)
print(_jsonObject)
try:
_param = {f"{param_name}": f"{param}"}
except KeyError:
_param = {f"{param_name}": f"{param}"}
print(_param)
_guild_conf.update(_param)
print(_jsonObject)
_jsonObject.update(_guild_conf)
_guild_conf = _jsonObject[f"{guild}"]
print(_jsonObject)
print(_guild_conf)
print(_param)
with open("prefix.json", "w") as _f:
json.dump(_jsonObject, _f)
_f.close()
write_json(929446191270330452, 'rr', '34')
write_json(929446191270330452, 'test1', '34')

23
test3.py Normal file
View File

@@ -0,0 +1,23 @@
my_dict = {'key': 'value'}
print(my_dict)
my_dict.update({'another_key': 'another_value'}) # Дополняем.
print(my_dict)
my_dict.update({'another_key': 'yet_another_value'}) # Обновляем.
print(my_dict)
my_dict.update({"subdict": {}})
subdict = my_dict['subdict']
print(my_dict)
print(subdict)
subdict.update({'subdictkey': 'subdictvalue'})
print(subdict)
print(my_dict)
subdict.update({'subdictkey2': 'subdictvalue2'})
print(my_dict)
subdict.update({'subdictkey': '33'})
print(my_dict)
my_dict.update({'testKey': 'testValue'})
print(my_dict)
print(my_dict)

19
test4.py Normal file
View File

@@ -0,0 +1,19 @@
from os import walk
f = []
print(f'{f}\n----------------')
for filenames in walk('audio'):
f.extend(filenames)
break
print(f'{f}\n----------------')
f = f[2]
print(f)
print(type(f))
i = 100
print(i)
i = i * 4
print(i)