TopSup
TopSup copied to clipboard
目前有个获取题目的接口可以添加上
具体可以查看https://github.com/lixinlong2014/666666 来源V2EX
确实可以用,只要稍微修改下编码格式,替换orc接口就可以搜索了。还避免了识别文字出错的情况。
@lixiang1991 欢迎提交代码 大神
@asseywang 因为本来也不是我自己写的,就把楼主链接的那个copy过来了,所以就不提交了,贴在这里吧。如果是在没有开始答题的情况下requests获取不到数据,楼主链接那里也提供了示例数据用来测试。
文件:GetQuestionTessAndroid.py
from PIL import Image
from common import screenshot, ocr, methods
from threading import Thread
import time
import requests, json
def get_question():
resp = requests.get(
'http://htpmsg.jiecaojingxuan.com/msg/current', timeout=5).text
# resp = requests.get('http://localhost:8000/sample.json', ).text
resp_dict = json.loads(resp)
if resp_dict['msg'] == 'no data':
print('................................')
question=None
rech=None
else:
question = resp_dict['data']['event']['desc']
question = question[question.find('.') + 1:question.find('?')]
choices = eval(resp_dict['data']['event']['options'])
rech=[]
for ch in choices:
rech.append(ch.decode('utf8'))
print('******************************************')
print(question)
print(choices)
print('******************************************')
return question, rech
while True:
question, choices = get_question()
if(question==None):
time.sleep(1)
continue
# 截图
# screenshot.check_screenshot()
#
# img = Image.open("./screenshot.png")
#
# # 文字识别
# ocr.ocr_img(img)
# t = time.clock()
# 用不同方法输出结果,取消某个方法在前面加上#
# # 打开浏览器方法搜索问题
# methods.run_algorithm(0, question, choices)
# # 将问题与选项一起搜索方法,并获取搜索到的结果数目
# methods.run_algorithm(1, question, choices)
# # 用选项在问题页面中计数出现词频方法
# methods.run_algorithm(2, question, choices)
# 多线程
m1 = Thread(methods.run_algorithm(0, question, choices))
m2 = Thread(methods.run_algorithm(1, question, choices))
m3 = Thread(methods.run_algorithm(2, question, choices))
m1.start()
m2.start()
m3.start()
# end_time = time.clock()
# print(end_time - t)
go = input('输入回车继续运行,输入 n 回车结束运行: ')
if go == 'n':
break
print('------------------------')