-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
33 lines (23 loc) · 873 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def remove_prefix_word(message, remove_num_words=1):
return " ".join(message.split()[remove_num_words:])
def read_config() -> dict:
with open("config_bot.cfg", "r") as f:
config_dict = {}
for line in f:
(key, val) = line.split()[0:2] # может измениться
if val in ["True", "False"]:
config_dict[key] = bool(val)
elif val.isdigit():
config_dict[key] = int(val)
else:
config_dict[key] = val
return config_dict
def update_config(key, val):
config_dict = read_config()
if key in config_dict.keys():
config_dict[key] = val
else:
print("there is no that key")
with open("config_bot.cfg", "w") as f:
for key in config_dict.keys():
f.write(f"{key} {config_dict[key]} \n")