-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
35 lines (32 loc) · 1.04 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
import ast
import platform
from duckduckgo_search import ddg_translate
def string_to_array(input_string):
try:
array = ast.literal_eval(input_string)
if isinstance(array, list):
return array
else:
raise ValueError("Input string is not a list.")
except (SyntaxError, ValueError) as e:
print(f"Error: {e}")
return None
def get_os_name():
os_name = platform.system()
if os_name == "Darwin":
return "MacOS"
elif os_name == "Windows":
return "Windows"
elif os_name == "Linux":
return "Linux"
else:
return "Unknown"
# Translates text to a specified language using the ddg_translate function from the duckduckgo_search package.
def translateTo(text, lang="en"):
translation = ddg_translate(text, to=lang)
if len(translation) > 0:
# only use the first translation
translation = translation[0]
if translation["detected_language"] != lang:
text = translation["translated"]
return text