def __inner_job(): start = time.time() text_binary = analyze_current_screen_text( directory=data_directory, compress_level=image_compress_level[0], crop_area=crop_areas[game_type], use_monitor=use_monitor) keywords = get_text_from_image(image_data=text_binary, timeout=timeout) if not keywords: print("text not recognize") return true_flag, real_question, question, answers = parse_question_and_answer( keywords) if game_type == "UC答题": answers = map(lambda a: a.rsplit(":")[-1], answers) print("~" * 60) print("{0}\n{1}".format(real_question, "\n".join(answers))) print("~" * 60) # ### refresh question # stdout_queue.put({ # "type": 0, # "data": "{0}\n{1}".format(question, "\n".join(answers)) # }) # # # notice baidu and craw # baidu_queue.put(( # question, answers, true_flag # )) # knowledge_queue.put(question) if enable_chrome: writer.send(question) noticer.set() summary = baidu_count(question, answers, timeout=timeout) summary_li = sorted(summary.items(), key=operator.itemgetter(1), reverse=True) if true_flag: recommend = "{0}\n{1}".format( "肯定回答(**): {0}".format(summary_li[0][0]), "否定回答( ): {0}".format(summary_li[-1][0])) else: recommend = "{0}\n{1}".format( "肯定回答( ): {0}".format(summary_li[0][0]), "否定回答(**): {0}".format(summary_li[-1][0])) print("*" * 60) print("\n".join( map(lambda item: "{0}: {1}".format(item[0], item[1]), summary_li))) print(recommend) print("*" * 60) ans = kwquery(real_question) print("-" * 60) print(wrap(" ".join(ans), 60)) print("-" * 60) end = time.time() # stdout_queue.put({ # "type": 3, # "data": "use {0} 秒".format(end - start) # }) print("use {0} 秒".format(end - start)) save_screen(directory=data_directory) time.sleep(1)
def test_baidu_word_count(self): a = baidu_count("全世界第一部公映的有声动画片是?", ["威利号汽船", "小熊维尼", "猫和老鼠"]) print(a)
def __inner_job(): start = time.time() text_binary = analyze_current_screen_text( directory=data_directory, compress_level=image_compress_level[0], crop_area=crop_areas[game_type], use_monitor=use_monitor) keywords = get_text_from_image(image_data=text_binary, ) if not keywords: print("text not recognize") return true_flag, real_question, question, answers = parse_question_and_answer( keywords) ## notice crawler to work # qwriter.send(real_question.strip("?")) # crawler_noticer.set() print('-' * 72) print(real_question) print('-' * 72) print("\n".join(answers)) # notice browser if enable_chrome: writer.send(question) noticer.set() search_question = pre_process_question(question) summary = baidu_count(search_question, answers, 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) print("*" * 72) if true_flag: print("肯定回答(**): ", summary_li[0][0]) print("否定回答( ): ", summary_li[-1][0]) else: print("肯定回答( ): ", summary_li[0][0]) print("否定回答(**): ", summary_li[-1][0]) print("*" * 72) # try crawler # retry = 4 # while retry: # if result_noticer.is_set(): # print("~" * 60) # print(stdreader.recv()) # print("~" * 60) # break # retry -= 1 # time.sleep(1) # result_noticer.clear() print("~" * 60) print(kwquery(real_question.strip("?"))) print("~" * 60) end = time.time() print("use {0} 秒".format(end - start)) save_screen(directory=data_directory)
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)