Beispiel #1
0
def run():
    while True:
        # 截图
        t = time.clock()
        screenshot.check_screenshot()
        img = Image.open("./screenshot.png")

        config_ = config.load_config()
        # question, choices = ocr.ocr_img_tess(img, config_)
        question, choices = ocr.get_question_and_choices(img, config_)
        question = filter_symbol(question)

        # 多线程
        m1 = Thread(methods.run_algorithm(0, question))
        m2 = Thread(methods.run_algorithm(1, question))
        m1.start()
        m2.start()

        end_time3 = time.clock()
        print('用时: {0}'.format(end_time3 - t))

        go = input('输入回车继续运行,输入 n 回车结束运行: ')
        if go == 'n':
            break
        print('------------------------')
Beispiel #2
0
async def send_request():
    resp = requests.get('http://htpmsg.jiecaojingxuan.com/msg/current',
                        timeout=4).text
    try:
        resp_dict = json.loads(resp)
    except json.JSONDecodeError as identifier:
        print('Passed JSONDecodeError')
        return '0'

    # print("resp_dict=",resp_dict)
    # print(answer_sets)
    test = 123
    if resp_dict['msg'] == 'no data':
        print('Waiting for question...')
        return '0'
    else:
        resp_dict = eval(str(resp))
        question = resp_dict['data']['event']['desc']
        question = question[question.find('.') + 1:question.find('?')]
        if question not in questions:
            questions.append(question)
            answers = eval(resp_dict['data']['event']['options'])
            answer_sets.append(answers)
            m2 = Thread(methods.run_algorithm(1, question, answers))
            m3 = Thread(methods.run_algorithm(2, question, answers))
            m2.start()
            m3.start()
            return question + '+' + str(answers)
        else:
            print('Waiting for new question...')
            return '0'
Beispiel #3
0
def questionAndAnswer():
    data = request.json
    title = data["title"]
    answers = data["answer"]
    __inner_job(title, answers)
    m2 = Thread(methods.run_algorithm(1, title, answers))
    m3 = Thread(methods.run_algorithm(2, title, answers))
    m2.start()
    m3.start()
    return ""
Beispiel #4
0
def start_browser_and_search(question, answers):
    print('拉起浏览器    ' + datetime.datetime.now().strftime('%H:%M:%S'))
    print('问题:  ' + question)
    print('1 %s' % answers[0])
    print('2 %s' % answers[1])
    print('3 %s' % answers[2])
    m1 = Thread(methods.run_algorithm(0, question, answers))
    m2 = Thread(methods.run_algorithm(1, question, answers))
    m3 = Thread(methods.run_algorithm(2, question, answers))
    m1.start()
    m2.start()
    m3.start()
    input('已暂停,按任意键继续')
Beispiel #5
0
def start_browser_and_search(question, answers, opBrowserFlag):
    if opBrowserFlag == True:
        print('拉起浏览器    ' + datetime.datetime.now().strftime('%H:%M:%S'))
        print('问题:  ' + question)
        m1 = Thread(methods.run_algorithm(0, question, answers))
        m1.start()
    else:
        print('1 %s' % answers[0])
        print('2 %s' % answers[1])
        print('3 %s' % answers[2])
        m2 = Thread(methods.run_algorithm(1, question, answers))
        m3 = Thread(methods.run_algorithm(2, question, answers))
        m2.start()
        m3.start()
Beispiel #6
0
        # imgByteArr = io.BytesIO()
        # region.save(imgByteArr, format="PNG")
        # image_data = imgByteArr.getvalue()

        # result = client.basicGeneral(image_data);
        # choices = []

        # for element in result["words_result"]:
        # choices.append (element["words"])

        # js = " window.open('http://www.acfun.cn/')" #可以看到是打开新的标签页 不是窗口
        # browser.execute_script(js)
        # browser.close()
        print(choices)
        if len(choices) != 0:
            # 多线程
            m2 = Thread(methods.run_algorithm(1, question, choices))
            m3 = Thread(methods.run_algorithm(2, question, choices))
            m2.start()
            m3.start()
        file = open(r".\test.txt", "a", encoding="utf-8")
        file.write(question)
        file.write("\n")
        for i in choices:
            file.write(i)
            file.write("\n")
        file.close()

    except:
        print("Error")
import wda
from PIL import Image
import os
import pytesseract
import webbrowser
import methods
import ocr
import screenshot

c = wda.Client()

# 截图
c.screenshot('screenshot.png')

img = Image.open("./screenshot.png")

# 文字识别
question, choices = ocr.ocr_img(img)

# 用不同方法输出结果

# 打开浏览器方法搜索问题
print(question)
print(choices)
methods.run_algorithm(1, question, choices)

# 将问题与选项一起搜索方法,并获取搜索到的结果数目
#methods.run_algorithm(1, question, choices)
# 用选项在问题页面中计数出现词频方法
#methods.run_algorithm(2, question, choices)