-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
126 lines (85 loc) · 2.97 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import json
import os
import shutil
import traceback
AUDIO_FOLDER_PATH = "./audio"
def get_bot_key() -> str:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["key"]
def get_username_key() -> str:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["db_username"]
def get_password_key() -> str:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["db_password"]
def get_database_key() -> str:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["db_database"]
def is_database_enabled() -> bool:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["db_enabled"]
def get_openai_key() -> str:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["openai_key"]
def get_hugging_chat_user_key() -> str:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["hugging_chat_user_key"]
def get_hugging_chat_password_key() -> str:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["hugging_chat_password_key"]
def is_debug_mode() -> bool:
with open("./data/keys.json") as file:
claves = json.loads(file.read())
return claves["debug"]
def get_sounds() -> list[str]:
return os.listdir(AUDIO_FOLDER_PATH)
def filter_list(elements: list[str], arg: str) -> list[str]:
return [item for item in elements if item.find(arg) != -1]
def get_sound_list_filtered(arg: str) -> list[list[str]]:
sounds = get_sounds()
sounds.sort()
filtered_sounds = filter_list(sounds, arg)
return generate_sound_list_format(filtered_sounds)
def get_sounds_list() -> list[list[str]]:
sounds = get_sounds()
sounds.sort()
return generate_sound_list_format(sounds)
def generate_sound_list_format(sounds: list[str]) -> list[list[str]]:
list_sounds = [[], [], []]
blank_space = "\u2800"
sounds = [sound.replace(".mp3", "") + blank_space * 2 for sound in sounds]
for x in range(len(sounds)):
sound = sounds[x]
pos = x % 3
list_sounds[pos].append(sound)
return list_sounds
def check_dir(dir_path: str):
if not os.path.exists(dir_path):
os.makedirs(dir_path)
def remove_file(path: str):
try:
if os.path.exists(path):
os.remove(path)
except Exception:
traceback.print_exc()
def remove_files(paths: list[str]):
for path in paths:
remove_file(path)
def remove_folder(dir_path: str):
try:
if os.path.exists(dir_path):
shutil.rmtree(dir_path)
except Exception:
traceback.print_exc()
def flatten(lists: list[list]) -> list:
return [element for sublist in lists for element in sublist]
if __name__ == "__main__":
pass