def main(): print('我来识别这个题目是啥!!!') text_binary = analyze_current_screen_text( label=vm_name, directory=data_directory ) if ocr_engine == 'baidu': print("用百度去OCR识别了!!!\n") keyword = get_text_from_image_baidu(image_data=text_binary, app_id=app_id, app_key=app_key, app_secret=app_secret, api_version=api_version, timeout=5) keyword = "".join([e.strip("\r\n") for e in keyword if e]) else: print("用汉王去OCR识别了!!!\n") keyword = get_text_from_image_hanwang(image_data=text_binary, appcode=hanwan_appcode) if not keyword: print("没识别出来,随机选吧!!!\n") print("题目出现的时候按F2,我就自动帮你去搜啦~\n") return keyword = pre_process_question(keyword) if len(keyword) < 2: print("没识别出来,随机选吧!!!\n") print("题目出现的时候按F2,我就自动帮你去搜啦~\n") return print("我用关键词:\" ", keyword, "\"去百度答案啦!") elem = browser.find_element_by_id("kw") elem.clear() elem.send_keys(keyword) elem.send_keys(Keys.RETURN) print("结果在浏览器里啦~\n") print("题目出现的时候按F2,我就自动帮你去搜啦~\n")
def main(): args = parse_args() timeout = args.timeout start = time.time() text_binary = analyze_current_screen_text(label=vm_name, directory=data_directory) if ocr_engine == 'baidu': # print("百度OCR!!!\n") keyword = get_text_from_image_baidu(image_data=text_binary, app_id=app_id, app_key=app_key, app_secret=app_secret, api_version=api_version, timeout=5) else: print("汉王 OCR\n") keyword = get_text_from_image_hanwang(image_data=text_binary, appcode=hanwan_appcode) if not keyword: print("Error-1 \n") # print("题目出现的时候按F2,我就自动帮你去搜啦~\n") return question = keyword[0:len(keyword) - 3] answers = keyword[len(keyword) - 3:] questions = "".join([e.strip("\r\n") for e in question if e]) # 去掉题目索引 for char, repl in [("11.", ""), ("12.", ""), ("11、", ""), ("12、", ""), ("1.", ""), ("2.", ""), ("3.", ""), ("4.", ""), ("5.", ""), ("6.", ""), ("7.", ""), ("8.", ""), ("9.", ""), ("10.", ""), ("1、", ""), ("2、", ""), ("3、", ""), ("4、", ""), ("5、", ""), ("6、", ""), ("7、", ""), ("8、", ""), ("9、", ""), ("10、", "")]: questions = questions.replace(char, repl) print("-" * 72) print("问题: | " + questions) end3 = time.time() print("-" * 50 + "{:4f} 秒".format(end3 - start) + "-" * 10) if len(questions) < 2: print("没识别出来,随机选吧!!!\n") return search_question = pre_process_question(questions) # ---------------题库关键词输出 p_ans = [] for i in range(0, 3): for char1, repl1 in [("A.", ""), ("B.", ""), ("C.", ""), ("A、", ""), ("B、", ""), ("C、", ""), ("A:", ""), ("B:", ""), ("C:", ""), ("A:", ""), ("B:", ""), ("C:", "")]: answers[i] = answers[i].replace(char1, repl1) p_ans.append(answers[i]) keys = p_ans[:] q_key = "" if (questions.find("《") != -1) & (questions.rfind("》") != -1): q_key = extraContext(questions, "《", "》") elif questions.find("\"") != -1: pii = questions.find("\"") pii1 = questions[pii + 1:].find("\"") if pii1 != -1: q_key = questions[pii + 1:pii + 1 + pii1] else: q_key = questions[pii + 1:pii + 5] elif questions.find("“") != -1: piii = questions.find("“") piii1 = questions[piii + 1:].find("”") if piii1 != -1: q_key = questions[piii + 1:piii + 1 + piii1] else: q_key = questions[piii + 1:piii + 5] elif questions.find("的") != -1: q_key = questions[questions.find("的") - 2:questions.find("的") + 2] elif questions.find("是") != -1: q_key = questions[questions.find("是") - 4:questions.find("是")] elif questions.find("哪") != -1: q_key = questions[questions.find("哪") - 2:questions.find("哪") + 3] else: q_key = questions[len(questions) / 2:len(questions) / 2 + 4] ansl = 0 if keys: fh = codecs.open('dict\dict.txt', "r", "utf-8") for line in fh.readlines(): mao = 0 if line.find(q_key) != -1: for key in keys: if (mao == 0) & (line.find(str(key)) != -1) & (len( str(key)) > 1): if (len(str(key)) < 3) & (is_number(key)): break print(colored(line, "blue")) ansl = 1 mao = 1 if ansl == 0: print(colored("《题库》未收录,查询失败!!!!!", "red")) else: print("问题: | " + questions) end2 = time.time() print("-" * 50 + "{:4f} 秒".format(end2 - start) + "-" * 10) # ---------------百度知道API summary = baidu_count(search_question, p_ans, timeout=timeout) summary_li = sorted(summary.items(), key=operator.itemgetter(1), reverse=True) data = [("《选项关联度》", "")] for a, w in summary_li: data.append((a, w)) table = AsciiTable(data) print(table.table) end1 = time.time() print("-" * 50 + "{:4f} 秒".format(end1 - start) + "-" * 10) print("-------百度查询摘要-------") abquery(questions, p_ans, q_key) end = time.time() print("-" * 50 + "{:4f} 秒".format(end - start) + "-" * 10)