This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (55 loc) · 2.32 KB
/
main.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
import window
from utils import ocr, logger
from MixacLib import cons
import yaml
import codecs
import os
import traceback
__DEFAULT_CONFIG__ = "# OCR语言\n" \
"# ch_sim - 中文\n" \
"# ja - 日语\n" \
"# en - 英语\n" \
"# 更多见:https://pic1.zhimg.com/80/v2-6b94055490da0821210d01fe5116facc_720w.jpg\n" \
"ocr-lang: ja\n" \
"# 支持以下接口:\n" \
"# baidu - 百度翻译\n" \
"# youdao - 有道智云\n" \
"translator: baidu\n" \
"\n" \
"# 翻译API APPID\n" \
"appid: APPID_HERE\n" \
"# 翻译API Key\n" \
"key: API_KEY_HERE"
__VERSION__ = "v0.2.0"
__BRANCH__ = "Master"
__REPO__ = "https://github.com/AFterNode/O2T-Translator"
if __name__ == "__main__":
try:
cons.console_title("AFterNode O2T Translator")
print("==========AFterNode O2T Translator==========")
print("Version: " + __VERSION__)
print("Branch: " + __BRANCH__)
print("Repo: " + __REPO__)
print("Loading configuration file...")
# 检测配置是否存在,不存在则写入默认配置
if not os.path.isfile("settings.yml"):
codecs.open("settings.yml", "w").write(__DEFAULT_CONFIG__)
print("Configuration file not found, generated a new.")
print("O2T generated a new configuration file, please check it and run again")
print("File name: settings.yml")
settings = yaml.load(codecs.open("settings.yml", "r"), yaml.FullLoader)
print("____________________")
print("O2T Translator Options")
print("OCR Language: " + settings["ocr-lang"])
print("Translator: " + settings["translator"])
print("____________________")
# 载入EasyOCR到内存
print("Loading OCR...")
ocr_reader = ocr.make_reader(settings['ocr-lang'])
# 启动主窗口
print("Starting main window...")
window.run(ocr_reader, settings)
except Exception as e:
print("Exception occurred, please commit an issue or send it to: [email protected]")
print(str(e))
traceback.print_exc()