-
Notifications
You must be signed in to change notification settings - Fork 2
/
Config.py
48 lines (41 loc) · 1.63 KB
/
Config.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
from yaml import CLoader as CLoader, CDumper as CDumper, load as yaml_load, dump as yaml_dump
import sys, os
NOPROXIES = {
"http": "",
"https": "",
}
isPacked = (getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'))
isInit = True
configPath = f'{os.path.dirname(sys.executable)}/TranslatorConfig.yaml' if isPacked else f'{os.path.dirname(os.path.abspath(__file__))}/TranslatorConfig.yaml'
def writeConfig(data: dict) -> None:
with open(configPath, mode='w', encoding='utf-8') as f:
yaml_dump(data, f, CDumper)
def readConfig() -> dict:
with open(configPath,encoding='utf-8') as f:
return yaml_load(f,CLoader)
def initConfig() -> None:
emptyData = {'YOUDAO_KEY': '',
'YOUDAO_SECRET': '',
'CAIYUN_TOKEN': '',
'BAIDU_APPID': '',
'BAIDU_SECRETKEY': '',
'TENCENT_SECERTID': '',
'TENCENT_SECERTKEY': '',
'XIAONIU_KEY': '',
'ALIYUN_KEY': '',
'ALIYUN_SECRET': '',
'SELECTED_TRANSLATORS': [],
'Hotkey_OCR': 'Ctrl + Space',
'OCR_APPID': 'c788b7aa',
'OCR_SECRET': 'ODFmODQwZWJmZDhlNTIzOTljNGI3OTcy',
'OCR_KEY': '7ec53833f14724cffb810c14e72eef0d',
'YOUDAO_FREE_RIDER': False,
'CAIYUN_FREE_RIDER': False,
'BAIDU_FREE_RIDER': False,
'TENCENT_FREE_RIDER': False,
'OPACITY': 95}
writeConfig(emptyData)
if(not os.path.exists(configPath)):
isInit = False
print('Config file not found, creating a new one...')
initConfig()