Skip to content

Commit

Permalink
修复了可能查询失败和检查连接的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Baoyan committed Mar 4, 2020
1 parent 8376811 commit dea6f43
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,4 @@ dmypy.json

# My configurations:
.vscode/
1activate.bat
1run_code.bat
build_exe/
Binary file added IDerek-xp.exe
Binary file not shown.
Binary file added IDerek.exe
Binary file not shown.
42 changes: 25 additions & 17 deletions IDerek.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
def is_connected():
try:
requests.get("http://www.baidu.com", timeout=5)
return True
except:
return False
return True


def right_key(event, editor): # 右键菜单
Expand Down Expand Up @@ -208,7 +208,7 @@ def wait_until_complete():
elif not idioms:
tkinter.messagebox.showinfo("", "请将待查询的成语单OCR(图片转文字)结果置于以上输入框内。")
elif is_searching != []:
search_definition_gui(search_definition_final_threading, "改错已应用。查询释义中。")
search_definition_gui(search_definition_final_threading, "已全部应用。查询释义中。")
elif is_searching == []:
change_disposable_widget(INTERFACE3)
text_box.insert("1.0", all_output_idiom)
Expand Down Expand Up @@ -270,14 +270,16 @@ async def fetch_for_first_searching(sem, idiom, session):
async with sem:
while True:
try:
async with session.get(url, params=params, headers=headers) as resp:
async with session.get(
url, params=params, headers=headers, timeout=30
) as resp:
idiom_html = await resp.text("utf-8", "ignore")
timeouts = 0
break
except:
idiom_html = ""
timeouts += 1
if timeouts == 20: # 连续五次超时
if timeouts == CONTINUOUS_TIMEOUTS_MAX: # 连续五次超时
tkinter.messagebox.showerror("", "请求超时,请重试,或重启电脑后重试。")
root.destroy()

Expand Down Expand Up @@ -314,14 +316,17 @@ def search_definition_again_threading(all_input_idiom):

is_searching = True

foo = [line for line in all_input_idiom.split() if line.find("->") != -1]
foo = [line for line in all_input_idiom.split("\n") if line.find("->") != -1]

user_corrects = {i.split("->")[0]: i.split("->")[1] for i in foo}
changed_words = user_corrects.values()
user_corrects = {i.split("->")[0].strip(): i.split("->")[1].strip() for i in foo}
changed_words = [x for x in user_corrects.values() if x]
idioms = [
user_corrects[idiom]
if idiom in user_corrects.keys() and user_corrects[idiom]
else idiom
idiom
for idiom in idioms
if idiom not in user_corrects.keys() or user_corrects[idiom]
]
idioms = [
user_corrects[idiom] if idiom in user_corrects.keys() else idiom
for idiom in idioms
]

Expand Down Expand Up @@ -364,7 +369,7 @@ async def fetch_for_final_searching(sem, idiom, session):
global last_search_time, searched_count, timeouts

if len(idiom) in banned_nums:
output_idiom = "██" + idiom
output_idiom = idiom + "(请修改此处)"
elif idiom in SPECIAL_WORDS.keys():
output_idiom = idiom + ":" + SPECIAL_WORDS[idiom]
else:
Expand All @@ -377,21 +382,23 @@ async def fetch_for_final_searching(sem, idiom, session):
async with sem:
while True:
try:
async with session.get(url, params=params, headers=headers) as resp:
async with session.get(
url, params=params, headers=headers, timeout=30
) as resp:
idiom_html = await resp.text("utf-8", "ignore")
timeouts = 0
break
except:
idiom_html = ""
timeouts += 1
if timeouts == 20: # 连续五次超时
if timeouts == CONTINUOUS_TIMEOUTS_MAX: # 连续五次超时
tkinter.messagebox.showerror("", "请求超时,请重试,或重启电脑后重试。")
root.destroy()

if get_def(idiom_html):
output_idiom = idiom + ":" + get_def(idiom_html)
else:
output_idiom = "██" + idiom
output_idiom = idiom + "(请修改此处)"

try:
last_search_time = time.time()
Expand Down Expand Up @@ -456,7 +463,8 @@ def output_definition():

is_searching = True
disposable_widgets = []
CHECK_INTERVAL = 1 # (s)
CONTINUOUS_TIMEOUTS_MAX = 30
CHECK_INTERVAL = 1
POOL = 10
corrects = {}

Expand Down Expand Up @@ -492,7 +500,7 @@ def output_definition():
"Label",
root,
"""输出释义会将成语自动追加至成语总集.txt中,释义自动追加至释义总集.txt中。
跳过改错建议的成语会以“██”标记,方便后期处理时改动文件""",
跳过改错建议的成语会在后面加上“(请修改此处)”,方便后期处理时改动文件""",
120,
8,
),
Expand All @@ -515,7 +523,7 @@ def output_definition():
20,
2,
lambda: search_definition_gui(
search_definition_final_threading, "已跳过余下改错建议。查询释义中。"
search_definition_final_threading, "已跳过。查询释义中。"
),
),
(
Expand Down
4 changes: 2 additions & 2 deletions 使用说明.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
���̳̿��ƺܳ���ʵ�ܶ�Ҳ�ܺö��������������ı��Ķ���һ�򱶣����Ķ������ʡ����Сʱ����

�����÷���
��Ҫһ�����ﵥ��һ��OCR��ͼƬת���֣��������ѳ��ﵥ��OCR���������Ϳ������г����ˡ������ڸ����൱�걸��ʹ��˵����
��Ҫһ�����ﵥ��һ��OCR��ͼƬת���֣��������ѳ��ﵥ��OCR����浽word����±��������Ҫ�����Ϳ������г����ˡ������ڸ����൱�걸��ʹ��˵����

���ڸ����ļ���
��׺Ϊpy��md��gitignore���ļ�ɾ��Ҳû�£����Ǹ������߿��ġ�
��Ҫ���е���exe�ļ���txt�ļ���json���ڴ������ݣ��⼸������ɾ���ұ�����ͬһ�ļ����С�
��Ҫ���е���exe�ļ������ڴ������ݵ���txt�ļ���json���⼸������ɾ���ұ�����ͬһ�ļ����С�
exe�ļ����ݲ���ϵͳ��һ��ɾһ����
xp����Windowsͨ�õġ����Dz���߼��൱��󣬲�֧���Զ��Ĵ������Ҿޣ������ޣ��ȣ���Windows xpֻ��������汾��
��׼��ֻ������Win7���ϲ���ϵͳ���ٶȷɿ죬֧���Զ��Ĵ��������������Dz��Խ���ٶ�Խ�졣
Expand Down

0 comments on commit dea6f43

Please sign in to comment.