博客太忙了,不想在继续维护了,代码开源
hashlib,base64,pykeyboard,pyautogui,numpy,opencv,json,time,requests等
本代码的ocr文字识别基于讯飞,识别率比百度好,所以改用讯飞,
与前面的那版相比,可以说前面那版放弃是正确的,百度太抠了,每个月免费500,讯飞注册就送10w,所以用这个了,具体怎么用,看代码把
if(oSession.uriContains("https://gateway.vocabgo.com/Student/ClassTask/SubmitAnswerAndSave")||oSession.uriContains("https://gateway.vocabgo.com/Student/StudyTask/SubmitAnswerAndSave")){
oSession.utilDecodeResponse();
oSession.SaveResponse("C:\\data\\response.txt",true);
oSession.SaveResponseBody("C:\\data\\responseBody.txt");
}
if(oSession.uriContains("https://gateway.vocabgo.com/Student/ClassTask/")){
oSession.utilDecodeResponse();
oSession.SaveResponseBody("C:\\data\\word_list.txt");
}
if(oSession.uriContains("https://gateway.vocabgo.com/Student/ClassTask/")){
oSession.utilDecodeResponse();
oSession.SaveResponseBody("C:\\data\\wordList.txt");
}
if(oSession.uriContains("https://gateway.vocabgo.com/Student/StudyTask/")){
oSession.utilDecodeResponse();
oSession.SaveResponseBody("C:\\data\\word_list.txt");
}
if(oSession.uriContains("https://gateway.vocabgo.com/Student/StudyTask/")){
oSession.utilDecodeResponse();
oSession.SaveResponseBody("C:\\data\\wordList.txt");
}
代码较长,逻辑基本完美,每次答题大于95分,需要继续开发的开以白嫖,感谢各位的支持
想入群的开以加:635032789
觉得不错,可以关注公众号:小白学习教程,或者进群赞助一波,博客会很开心
#-*- coding: utf-8 -*-
import hashlib
import base64
from pykeyboard import PyKeyboard
import pyautogui
import numpy as np
import cv2 as cv
import os
import json
import time
import random
import requests
import openpyxl
import xlrd
from re import sub,findall,search
import sys
sys.setrecursionlimit(100000) #例如这里设置为十万
# print('请确认已经注册的讯飞识别的应用,并在官网将自己的ip设置为白名单')
print('因为ocr识别率不是很高,对一些识别不到的题目,我加入了逻辑,一般情况可以顺利的完成每个list')
print('感谢大家的支持')
print('欢迎加群719352964')
# bt=input('如果你的list已经改名字了,请输入1,其他的输入0:')
# UserToken=input('请输入Usertoken:')
bt=input('自学输入1,其余输入0:')
id=input('请输入讯飞的APPID:')
key=input('请输入讯飞的API_KEY:')
print('确保你的界面在单词页,按回车继续')
input("Entry the any key to exit")
with open("C:/data/2.txt", "r") as f:
UserToken = f.readline()
# print(UserToken)
kkk = PyKeyboard()
th=random.randrange(1,3,1)
# thh=random.randrange(1,5,1)
# thhh=random.choice([1,1,2.5,3,5.5,7.5,6])
try:
f1 = open('C:/data/wordList.txt', 'r', encoding='utf-8')
except:
print('未找到wordList')
headers={
'UserToken': UserToken,
}
word_list=json.load(f1)
try:
if int(bt)==1:
course_id = word_list['data']['course_id']
list_id = word_list['data']['list_id']
else:
course_id = word_list['data']['course_id']
list_id = word_list['data']['word_list'][1]['list_id']
except:
print('word_list文件不正确请按照流程操作')
print('退回到主界面选择单词书之后再打开软件')
word_list_js={}
for j in range(len(word_list['data']['word_list'])):
word = word_list['data']['word_list'][j]['word']
url = 'https://gateway.vocabgo.com/Student/Course/StudyWordInfo?course_id=' + course_id + '&list_id=' + list_id + '&word=' + word + '×tamp=1587916524392&versions=1.0'
r = requests.get(url, headers=headers, verify=False)
word_js = json.loads(r.text)
word_list_js[word]=word_js['data']['options']
print('-------------加载中-------------')
print('--------------------------------加载成功----------------------------------------------')
# print(json.dumps(word_list_js))
print('确保你已经完成了第一题,然后按回车继续')
input("Entry the any key to exit")
# iddd=input('请输入讯飞的APPID:')
# idddd=input('请输入讯飞的API_KEY:')
# thh = 0.5
thh = input('请输入答题间隔时间0.5,1,2 ,3 ,4 ,5 等等:')
# fb1= input('请输入:')
# fb2= input('请输入:')
fb1= 400
fb2= 1000
input("Entry the any key to exit")
# fb=()
# if fb==1:
# fb1=400
# fb2=1000
# else:
# pass
# answers=[]
while True:
try:
f = open('C:/data/responseBody.txt', 'r', encoding='utf-8')
except:
print('未找到responseBody')
t1 = cv.getTickCount()
# time.sleep(th)
time.sleep(float(thh))
js = json.load(f)
# aaaa=[]
answer = []
try:
if js['data']['topic_mode']==11:
mode_11_content=js['data']['stem']['content']
# print(mode_11_content)
time.sleep(0.5)
for key,value in word_list_js.items():
# print(len(value))
for q in range(len(value)):
# print(value[q]['content']['example'])
for w in range(len(value[q]['content']['example'])):
# print(value[q]['content']['example'][w]['sen_content'])
if value[q]['content']['example'][w]['sen_content']==mode_11_content :
pattern=value[q]['content']['mean'].replace('s','a').replace('ing','').replace('ed','').replace('e','h').replace(' ','').replace('/','').replace('ed','').replace("(.*?)|{.*?}|[.*?]",'').replace('…','aa').replace('adv','').replace('adj','').replace(';','').replace('noun','').replace('verb','').replace(',','').replace('vhrb','').replace('ing','')
# patternn =re.sub(u"\\(.*?\\)|\\{.*?\\}", "",value[q]['content']['mean'].replace(' ','').replace('adj','').replace(';','').replace('noun','').replace('verb','').replace(',',''))
paaaa=sub("(.*?)", '', pattern)
answer.append(paaaa)
else:
pass
# pattern =value[q]['content']['mean'].replace(' ','').replace('adj','').replace(';','').replace('noun','').replace('verb','').replace(',','')
# # answer.append(pattern)
# answer=re.sub(u"(.*?)|{.*?}|[.*?]", "",pattern)
# print(value[q]['content']['mean'].replace(';','').replace('noun','').replace('verb',''))
# print(patternn)
# print('------------------------------------------------------')
elif js['data']['topic_mode']==22:
mode_22_content=js['data']['stem']['content']
# print(mode_22_content)
# print(word_list_js[mode_22_content])
for r in range(len(word_list_js[mode_22_content])):
for t in range(len(js['data']['options'])):
# answer=[]
if js['data']['options'][t]['content']==word_list_js[mode_22_content][r]['content']['mean']:
paa=js['data']['options'][t]['content'].replace('s','a').replace('ed','').replace('e','h').replace('ing','').replace('ed','').replace('/','').replace(';','').replace(' ','').replace('adv','').replace('noun','').replace('…', '的').replace('verb','').replace('adj','').replace(',','').replace('adv','').replace(' ','').replace('vhrb','')
# try:
# time.sleep(0.5)
pa =sub("(.*?)", '', paa)
# paaa=paa
answer.append(pa)
# except:
# answer.append(pa)
# answer.append(js['data']['options'][t]['content'].replace(';','').replace(' ','').replace('adv','').replace('noun','').replace('…', '的').replace('verb','').replace('adj','').replace(',','').replace('adv','').replace("(.*?)",'').replace(' ',''))
# print(js['data']['options'][t]['content'].replace(';','').replace('noun','').replace('verb','').replace(',',''))
else:
paa = (word_list_js[mode_22_content][r]['content']['mean'].replace('s','a').replace('ed','').replace('e','h').replace('ed','').replace('…', 'aa').replace(';','').replace('noun','').replace('verb','').replace(',','').replace(' ','').replace('e','h').replace('adj','').replace('adv','').replace('vhrb','').replace('ing',''))
# if re.sub in dict:
pa = sub("(.*?)|{.*?}|[.*?]", '',paa)
# paaa=dict(pa)
# aaaa.append(paa)
# answer=re.sub("(.*?)|{.*?}|[.*?]", '',aaaa)
# except:
answer.append(pa)
# paa = [mode_22_content][r]['content']['mean'].replace('…', '的').replace(';','').replace('noun','').replace('verb','').replace(',','').replace(' ','').replace('adj','').replace('adv','')
# answer.append(word_list_js[mode_22_content][r]['content']['mean'].replace("(.*?)",'').replace('…', '的').replace(';','').replace('noun','').replace('verb','').replace(',','').replace(' ','').replace('adj','').replace('adv',''))
# print(word_list_js[mode_22_content][r]['content']['mean'].replace('…', '的').replace(';','').replace('noun','').replace('verb','').replace(',',''))
# time.sleep(0.5)
# print('--------------------------------------')
elif js['data']['topic_mode']==31:
for y in range(len(js['data']['stem']['remark'])):
answer.append(js['data']['stem']['remark'][y]['relation'].replace('s','a').replace('-', '').replace('ed','').replace('e','h').replace('vhrb','').replace('/','').replace('s','').replace('ing',''))
# print(js['data']['stem']['remark'][y]['relation'])
# time.sleep(0.5)
# print('----------------------------------------')
elif js['data']['topic_mode'] == 32:
mode_32_content=js['data']['stem']['remark']
for key,value in word_list_js.items():
# print(len(value))
for q in range(len(value)):
# print(value[q]['content']['example'])
for w in range(len(value[q]['content']['usage'])):
if mode_32_content in value[q]['content']['usage'][w]:
a = value[q]['content']['usage'][w].replace('s','a').replace('adv', '').replace('ing','').replace("'s",'').replace('ed','').replace('/','').replace('e','h').replace('ing','').replace('vhrb','') # .replace('{', '').replace('}', '').replace(';','')
# # reg='[\u4e00-\u9fa5]'
a = sub("[\u4e00-\u9fa5]*", '', str(a))
# a=sub("[\u4e00-\u9fa5]*","",str(a))
# a=sub(":*","",str(a))
# a=sub(' *{',"','",str(a))
# a = sub(' *}', "", str(a))
f = lambda a: [e.lower() for e in findall(r'\b\w+\b', a)]
answer = f(a)
# del (answer[-1])
# c=value[q]['content']['usage'][w].replace('{','').replace('}','').replace(';','').replace(' ','')
# reg = '[\u4e00-\u9fa5]'
# answers = sub(reg, '', c)
#
# answer.append(answers)
# # print(value[q]['content']['usage'][w])
# time.sleep(0.5)
# print('------------------------------------------')
elif js['data']['topic_mode'] == 42:
mode_42_content=js['data']['stem']['remark']
for key,value in word_list_js.items():
# print(len(value))
for q in range(len(value)):
# print(value[q]['content']['example'])
for w in range(len(value[q]['content']['example'])):
if mode_42_content == value[q]['content']['example'][w]['sen_mean_cn']:
answer.append(key.replace('s','a').replace('ed','').replace('ing','').replace('ing','').replace('e','h').replace('vhrb','').replace('/',''))
# print(key)
# time.sleep(0.5)
elif js['data']['topic_mode'] == 51:
mode_51_content=js['data']['stem']['remark']
for key,value in word_list_js.items():
# print(len(value))
for q in range(len(value)):
# print(value[q]['content']['example'])
for w in range(len(value[q]['content']['usage'])):
if mode_51_content in value[q]['content']['usage'][w]:
# print(value[q]['content']['usage'][w])
tran_answer1 = ''
search('{',value[q]['content']['usage'][w])
# print(js['data']['stem']['content'])
# print(re.search('{', js['data']['stem']['content']).span()[0])
# print(re.search('}', js['data']['stem']['content']).span()[1])
before = search('{', value[q]['content']['usage'][w]).span()[0]
after = search('}', value[q]['content']['usage'][w]).span()[1]
for s in range(before + 1, after - 1):
# print(js['data']['stem']['content'][s])
tran_answer1 = (tran_answer1 + value[q]['content']['usage'][w][s]).lower()
# print(tran_answer1)
answer.append(tran_answer1)
# print('------------------------------------------------')
# time.sleep(0.5)
except:
print('本任务已经完成,按ctrl+c 退出',)
input("Entry the any key to exit")
print('1111',answer)
# time.sleep(0.5)
# time.sleep(th)
img = pyautogui.screenshot(region=[0, 130, 480, 850]) # x,y,w,h
img.save('./1/answer.jpg')
# time.sleep(th)
## 2图片灰度处理
# def access_pixels(image):
# height, width, channels = image.shape
# # print("width:%s,height:%s,channels:%s" % (width, height, channels))
#
# for row in range(height):
# for list in range(width):
# for c in range(channels):
# pv = image[row, list, c]
# image[row, list, c] = 255 - pv
# # cv.imshow("AfterDeal", image)
#
#
# src = cv.imread('./1/answer.jpg')
# # cv.imshow('OriginalImage', src)
#
# # t1 = cv.getTickCount()
# access_pixels(src)
# # t2 = cv.getTickCount()
# # print("time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
src = cv.imread("1/answer.jpg", 1)
Img = 255 - src
cv.imwrite('2/answer.jpg', Img)
indir = "./2/"
outdir = "./3/"
cout = 0
for fileName in os.listdir(indir):
if fileName == '.DS_Store':
continue
cout = cout + 1
# print(cout)
# print(fileName)
img_dir = os.path.join(indir, fileName) # 获取图片的名字
# print(img_dir)
src = cv.imread(img_dir) # 读取图片
h1, w1 = src.shape[:2]
# print(h1, w1) # 打印长和宽
r = 1 / 2 # 缩小倍数
# 进行缩放
dst = cv.resize(src, (int(w1 / r), int(h1 / r)), interpolation=cv.INTER_CUBIC) # 使用双立方插值
h2, w2 = dst.shape[:2]
# print(h2, w2) # 打印长和宽
# print(outdir + fileName)
cv.imwrite(outdir + fileName, dst)
I = cv.imread('./3/answer.jpg', flags=0)
aa = 2
Oa = I * float(aa)
Oa[Oa > 255] = 255
Oa = np.round(Oa)
Oa = Oa.astype(np.uint8)
cv.imwrite('./4/answer.jpg', Oa)
URL = "http://webapi.xfyun.cn/v1/service/v1/ocr/general"
APPID = id
API_KEY = key
def getHeader():
# 当前时间戳
curTime = str(int(time.time()))
# 支持语言类型和是否开启位置定位(默认否)
param = {"language": "cn|en", "location": "true"}
param = json.dumps(param)
paramBase64 = base64.b64encode(param.encode('utf-8'))
m2 = hashlib.md5()
str1 = API_KEY + curTime + str(paramBase64, 'utf-8')
m2.update(str1.encode('utf-8'))
checkSum = m2.hexdigest()
# 组装http请求头
header = {
'X-CurTime': curTime,
'X-Param': paramBase64,
'X-Appid': APPID,
'X-CheckSum': checkSum,
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
}
return header
# 上传文件并进行base64位编码
with open(r'./4/answer.jpg', 'rb') as f:
f1 = f.read()
f1_base64 = str(base64.b64encode(f1), 'utf-8')
data = {
'image': f1_base64
}
# h=list()
r = requests.post(URL, data=data, headers=getHeader())
result = str(r.content, 'utf-8')
# print(result)
re = json.loads(result)
# print(re['data']['block'][0]['line'])
# print(r)
print('正在答题,请不要动鼠标')
# i=0
try:
i = 0
qq = []
while i < len(re['data']['block'][0]['line']):
t = re['data']['block'][0]['line'][i]['location']['top_left']
# e=print((t['x'],t['y']))
i += 1
qq.append(t)
# q.sort(reverse=False)
# print('识别到的坐标:',qq)
# print('正在答题,请不要懂鼠标')
# t2 = cv.getTickCount()
# print("every topic time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
j = 0
h = []
while j < len(re['data']['block'][0]['line']):
c = re['data']['block'][0]['line'][j]['word']
# w= re['data']['block'][0]['line'][i]['top_left']
k = c[-1]["content"].replace(';', ';').replace("'s",'').replace("s",'a').replace('adj', '').replace('...', '的').replace('忧', '').replace(
';', '').replace('adv', '').replace(',', ',').replace('ed','') \
.replace('verb', '').replace(',', '').replace(']', '').replace('/', '').replace('…', '的').replace(
'noun', '').replace('A','a').replace('B','b').replace('C','c').replace('D','d').replace('E','e').replace('F','f').replace('G','g').replace('H','h') \
.replace('prep', '').replace('督', '').replace('愚蠢的荒缪的可笑的', '').replace('-', '') \
.replace('发出爆裂声避啪作响', '').replace('警', '').replace('擎', '').replace('表露', '').replace('显示', '') \
.replace(':', '').replace('←','').replace('e','h') \
.replace('I', 'i').replace('J', 'j').replace('K', 'k').replace('M', 'm').replace('O', 'o').replace('P', 'p')\
.replace('Q', 'q').replace('R', 'r').replace('/','').replace('ing','').replace('S','s').replace('T','t')\
.replace('U','u').replace('V','v').replace('W','w').replace('X','x').replace('Y','y').replace('_', '')\
.replace('Z','z').replace('e','h').replace('ing','').replace('0', '').replace('[', '').replace(']', '')\
.replace("'s",'').replace('1', '').replace('7', '').replace('8', '').replace('9', '')\
.replace('2', '').replace('3', '').replace('4', '').replace('5', '').replace(':','').replace('6', '').replace('(', '').replace(')', '').replace('。','')
# .replace('油', '')
j += 1
h.append(k)
# h=list(c[-1]["content"])
# h.append(c)
# print('识别到的答案:',h)
except:
print('服务器已关闭,请在指定时间使用,谢谢')
print('识别到的答案:', h)
# 印刷文字识别 webapi 接口地址
# time.sleep(th)
try:
# try:
# while True:
if answer:
i = 0
shibie = 0
zuobiao = []
while i < len(answer) and shibie < len(h):
set_lst = h[:]
for kk in answer:
if kk in set_lst:
continue
else:
set_lst.append(kk)
# print('2222',set_lst)
if len(set_lst) == len(h):
# 答案在识别的里面
if len(answer) - int(1) == len(set(answer)) :
if len(answer) <4 :
zib = [((qq[-2]['x']) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('150')),
((qq[-1]['x']) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('145')),
((qq[-3]['x']) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('150'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[2])
else:
zib = [((qq[-2]['x']) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('150')),
((qq[-1]['x']) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('145')),
((qq[-3]['x']) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('150')),
((qq[-4]['x']) / int('2') + int('50'), (qq[-4]['y']) / int('2') + int('145')),
((qq[-5]['x']) / int('2') + int('50'), (qq[-5]['y']) / int('2') + int('150')),
((qq[-6]['x']) / int('2') + int('50'), (qq[-6]['y']) / int('2') + int('150'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[2])
time.sleep(0.5)
pyautogui.click(zib[3])
time.sleep(0.5)
pyautogui.click(zib[4])
time.sleep(0.5)
pyautogui.click(zib[5])
# pyautogui.click(158, 448)
# time.sleep(0.5)
# pyautogui.click(362, 448)
# time.sleep(0.5)
# pyautogui.click(158, 513)
# time.sleep(0.5)
# pyautogui.click(362, 513)
# time.sleep(0.5)
# pyautogui.click(158, 578)
# time.sleep(0.5)
# pyautogui.click(362, 578)
# time.sleep(0.5)
# pyautogui.click(158, 631)
break
elif len(answer) > 4 and ((len(answer) + int(2) == len(h))or len(answer) == len(h)):
zib = [(((qq[-1]['x'])) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('140')),
(((qq[-2]['x'])) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('140')),
(((qq[-3]['x'])) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('140')),
(((qq[-4]['x'])) / int('2') + int('50'), (qq[-4]['y']) / int('2') + int('140')),
(((qq[-5]['x'])) / int('2') + int('50'), (qq[-5]['y']) / int('2') + int('140')),
(((qq[-6]['x'])) / int('2') + int('50'), (qq[-6]['y']) / int('2') + int('140'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[2])
time.sleep(0.5)
pyautogui.click(zib[3])
time.sleep(0.5)
pyautogui.click(zib[4])
time.sleep(0.5)
pyautogui.click(zib[5])
break
else:
p = h.index(answer[i])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
time.sleep(0.5)
i += 1
elif h[-1]=='确认':
#进入了一种题型
time.sleep(2)
break
# elif ((h[0] >= u'\u0041' and h[0]<=u'\u005a') or (h[0] >= u'\u0061' and h[0]<=u'\u007a')) and (h[1] >= u'\u4e00' and h[1]<=u'\u9fa5') and ((h[-3] >= u'\u0041' and h[-3]<=u'\u005a') or (h[-3] >= u'\u0061' and h[-3]<=u'\u007a')) and ((h[-2] >= u'\u0041' and h[-2]<=u'\u005a') or (h[-2] >= u'\u0061' and h[-2]<=u'\u007a')):
# # 进入乱选,选词出现了只选一个,然后随机选
#
#
# pyautogui.click(155, 380)
# time.sleep(0.5)
# pyautogui.click(361, 380)
# time.sleep(0.5)
# pyautogui.click(157, 465)
# time.sleep(0.5)
# pyautogui.click(361, 465)
# time.sleep(0.5)
# pyautogui.click(157, 517)
# time.sleep(0.5)
# pyautogui.click(361, 517)
# time.sleep(0.5)
# pyautogui.click(157, 556)
# time.sleep(0.5)
# pyautogui.click(361, 556)
# time.sleep(0.5)
# pyautogui.click(240, 550)
# break
elif len(set(answer))!=len(answer) and len(answer) >3 : #and ((h[-2] >= u'\u0041' and h[-2 ]<=u'\u005a') or (h[-2] >= u'\u0061' and h[-2]<=u'\u007a')):
# 答案有重复,并且答案长度大于3,进入听词选单词
if len(answer)==4:
if answer[0] not in h:
pyautogui.click(158, 365)
time.sleep(0.5)
pyautogui.click(158, 448)
time.sleep(0.5)
pyautogui.click(362, 391)
time.sleep(0.5)
pyautogui.click(362, 448)
# time.sleep(0.5)
# pyautogui.click(400, 1000)
break
else :
p =h.index(answer[0])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# x = int(qq[-2]['x']) / int('2') + int('50')
# y = int(qq[-2]['y']) / int('2') + int('140')
pyautogui.click(x, y)
# time.sleep(0.5)
break
elif len(answer)==8:
if answer[0] in h and answer[4] not in h:
p = h.index(answer[0])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# x = int(qq[-2]['x']) / int('2') + int('50')
# y = int(qq[-2]['y']) / int('2') + int('140')
pyautogui.click(x, y)
# time.sleep(0.5)
break
elif answer[4] in h and answer[0] not in h:
p = h.index(answer[4])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# x = int(qq[-2]['x']) / int('2') + int('50')
# y = int(qq[-2]['y']) / int('2') + int('140')
pyautogui.click(x, y)
# time.sleep(0.5)
break
else:
pyautogui.click(158, 365)
time.sleep(0.5)
pyautogui.click(158, 448)
time.sleep(0.5)
pyautogui.click(362, 391)
time.sleep(0.5)
pyautogui.click(362, 448)
# time.sleep(0.5)
# pyautogui.click(400, 1000)
break
elif len(answer)==12 :
if answer[0] in h and (answer[4] not in h or answer[8] not in h):
p = h.index(answer[0])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# x = int(qq[-2]['x']) / int('2') + int('50')
# y = int(qq[-2]['y']) / int('2') + int('140')
pyautogui.click(x, y)
# time.sleep(0.5)
break
elif answer[4] in h and (answer[0] not in h or answer[8] not in h):
p = h.index(answer[4])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# x = int(qq[-2]['x']) / int('2') + int('50')
# y = int(qq[-2]['y']) / int('2') + int('140')
pyautogui.click(x, y)
# time.sleep(0.5)
break
elif answer[8] in h and ( answer[0] not in h or answer[4] not in h):
p = h.index(answer[8])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# x = int(qq[-2]['x']) / int('2') + int('50')
# y = int(qq[-2]['y']) / int('2') + int('140')
pyautogui.click(x, y)
# time.sleep(0.5)
break
else:
zib = [((qq[-2]['x']) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('150')),
((qq[-1]['x']) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('145'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
# pyautogui.click(400, 1000)
break
else:
# pyautogui.click(158, 395)
# time.sleep(0.5)
# pyautogui.click(353, 395)
# time.sleep(0.5)
pyautogui.click(158, 439)
time.sleep(0.5)
pyautogui.click(353, 448)
time.sleep(0.5)
pyautogui.click(158, 508)
time.sleep(0.5)
pyautogui.click(362, 508)
time.sleep(0.5)
pyautogui.click(158, 576)
time.sleep(0.5)
pyautogui.click(362, 576)
break
elif len(set_lst) != len(h):
#识别到的里面没有答案的单词,第一种情况,有' ,第二钟情况有特殊符号 , 第三种情况是单词拼写 ,第四种情况识别错误
if h[-1] == '提交':
# print('你已经进入单词拼写模块了,但是本软件并未对本题型做出自动答题,请等待后续的优化,\n 打你可以手动输入答案,答案在下方')
# zuo=[q[0]]
# print("答案:", answers)
# –模拟键盘输入字符串
# print(zuo)
# if len(answer)==0:
# pyautogui.click(249, 360)
zib = [((qq[0]['x']) / int('2') + int('50'), (qq[0]['y']) / int('2') + int('150')),
((qq[-1]['x']) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('145'))]
# if len(h[0]) != 3:
# pyautogui.click(80, 176)
kkk.type_string(answer[0])
# time.sleep(th)
time.sleep(2)
pyautogui.click(zib[1])
# time.sleep(0.5)
break
# pyautogui.click(400, 1000)
elif (h[0] >= u'\u0041' and h[0] <= u'\u005a') or (h[0] >= u'\u0061' and h[0] <= u'\u007a') and (h[1] >= u'\u0041' and h[1] <= u'\u005a') or (h[1] >= u'\u0061' and h[1] <= u'\u007a') \
and (h[2] >= u'\u4e00' and h[2] <= u'\u9fa5') and (h[3] >= u'\u4e00' and h[3]<=u'\u9fa5') :
if (h[-1] >= u'\u4e00' and h[-1]<=u'\u9fa5') or (h[-3] >= u'\u4e00' and h[-3]<=u'\u9fa5') :
# 多选识别错误,进入这里
zib = [((qq[4]['x']) / int('2') + int('50'), (qq[4]['y']) / int('2') + int('150')),
((qq[5]['x']) / int('2') + int('50'), (qq[5]['y']) / int('2') + int('145')),
((qq[6]['x']) / int('2') + int('50'), (qq[6]['y']) / int('2') + int('150')),
((qq[7]['x']) / int('2') + int('50'), (qq[7]['y']) / int('2') + int('145'))]
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[2])
time.sleep(0.5)
pyautogui.click(zib[3])
break
else:
zib = [((qq[-2]['x']) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('150')),
((qq[-1]['x']) / int('2') + int('80'), (qq[-1]['y']) / int('2') + int('145')),
((qq[-3]['x']) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('150')),
((qq[-4]['x']) / int('2') + int('50'), (qq[-4]['y']) / int('2') + int('145')),
((qq[-5]['x']) / int('2') + int('50'), (qq[-5]['y']) / int('2') + int('150'))]
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[2])
time.sleep(0.5)
pyautogui.click(zib[3])
time.sleep(0.5)
pyautogui.click(zib[4])
break
# elif len(answer)==len(h):
# # if len(h) > 4 :
# # zib = [(((qq[-1]['x'])) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('140')),
# # (((qq[-2]['x'])) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('140')),
# # (((qq[-3]['x'])) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('140')),
# # (((qq[-4]['x'])) / int('2') + int('50'), (qq[-4]['y']) / int('2') + int('140')),
# # (((qq[-5]['x'])) / int('2') + int('50'), (qq[-5]['y']) / int('2') + int('140')),
# # (((qq[-6]['x'])) / int('2') + int('50'), (qq[-6]['y']) / int('2') + int('140'))]
# pyautogui.click(135,371)
# time.sleep(0.5)
# pyautogui.click(344,371)
# time.sleep(0.5)
# pyautogui.click(135,443)
# time.sleep(0.5)
# pyautogui.click(344,443)
# time.sleep(0.5)
# pyautogui.click(135,504)
# time.sleep(0.5)
# pyautogui.click(344,504)
# time.sleep(0.5)
# pyautogui.click(135, 570)
# time.sleep(0.5)
# pyautogui.click(344, 570)
# time.sleep(0.5)
# pyautogui.click(144, 631)
# time.sleep(0.5)
# pyautogui.click(344, 631)
# break
# else:
# zib = [(((qq[-1]['x'])) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('140')),
# (((qq[-2]['x'])) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('140')),
# (((qq[-3]['x'])) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('140'))]
# pyautogui.click(zib[0])
# time.sleep(0.5)
# pyautogui.click(zib[1])
# time.sleep(0.5)
# pyautogui.click(zib[2])
# break
# pass
elif ((h[-len(h)] >= u'\u0041' and h[-len(h)] <= u'\u005a') or (
h[-len(h)] >= u'\u0061' and h[-len(h)] <= u'\u007a')) and (
(h[-len(h) + 1] >= u'\u0041' and h[-len(h) + 1] <= u'\u005a') or (
h[-len(h) + 1] >= u'\u0061' and h[-len(h) + 1] <= u'\u007a')) and (
(h[-len(h) + 2] >= u'\u0041' and h[-len(h) + 2] <= u'\u005a') or (
h[-len(h) + 2] >= u'\u0061' and h[-len(h) + 2] <= u'\u007a')) and (
(h[-1] >= u'\u0041' and h[-1] <= u'\u005a') or (h[-1] >= u'\u0061' and h[-1] <= u'\u007a')):
# 识别到的第一个,第二个第三个并且最后一个元素都是英文, 进入了英文句子选英文单词
# zib = [((q[-2]['x']) / int('2') + int('130'), (q[-2]['y']) / int('2') + int('150')),
# ((q[-1]['x']) / int('2') + int('80'), (q[-1]['y']) / int('2') + int('145')),
# ((q[-3]['x']) / int('2') + int('130'), (q[-3]['y']) / int('2') + int('150')),
# ((q[-4]['x']) / int('2') + int('80'), (q[-4]['y']) / int('2') + int('145'))]
if len(answer)==2 and answer[0] in h:
p = h.index(answer[0])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
break
# time.sleep(0.5)
elif len(answer)==2 and answer[1] in h :
p = h.index(answer[1])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
break
# time.sleep(0.5)
else:
if answer[0] not in h :
zib = [(((qq[-1]['x'])) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('140')),
(((qq[-2]['x'])) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('140')),
(((qq[-3]['x'])) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('140'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[2])
# time.sleep(0.5)
break
else:
p = h.index(answer[i])
zuobiao = dict(qq[p])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
# time.sleep(0.5)
i +=1
elif ((h[0] >= u'\u4e00' and h[0]<=u'\u9fa5') or (h[1] >= u'\u4e00' and h[1]<=u'\u9fa5')) and ((h[-1] >= u'\u0041' and h[-1] <= u'\u005a') or (
h[-1] >= u'\u0061' and h[-1] <= u'\u007a')):
# else:
xin = [h[-3], h[-2], h[-1]]
zuo = [qq[-3], qq[-2], qq[-1]]
d = [y for y in answer if y not in xin] # 在list2列表中而不在list1列表中
# print('将识别到的单词拿出来',xin)
xin.append(d[0])
print('新的识别到的答案:',xin)
if len(answer) >4 :
pyautogui.click(135, 371)
time.sleep(0.5)
pyautogui.click(344,371)
time.sleep(0.5)
pyautogui.click(135,443)
time.sleep(0.5)
pyautogui.click(344,443)
time.sleep(0.5)
pyautogui.click(135,504)
time.sleep(0.5)
pyautogui.click(344,504)
time.sleep(0.5)
pyautogui.click(135, 570)
time.sleep(0.5)
pyautogui.click(344, 570)
time.sleep(0.5)
pyautogui.click(144, 631)
time.sleep(0.5)
pyautogui.click(344, 631)
break
else:
if (xin[-2] >= u'\u4e00' and xin[-2]<=u'\u9fa5') or (xin[-1] >= u'\u4e00' and xin[-1]<=u'\u9fa5'):
pyautogui.click(158, 365)
time.sleep(0.5)
pyautogui.click(86, 365)
time.sleep(0.5)
pyautogui.click(86, 416)
time.sleep(0.5)
pyautogui.click(158, 448)
time.sleep(0.5)
pyautogui.click(362, 391)
time.sleep(0.5)
pyautogui.click(88, 484)
time.sleep(0.5)
pyautogui.click(362, 417)
time.sleep(0.5)
pyautogui.click(362, 354)
break
# time.sleep(0.5)
# pyautogui.click(400, 1000)
# time.sleep(th)
else:
# print('新坐标',zuo)
# i+=1
t = -3
zb = []
while t < 0:
zbi = dict(qq[int(t)])
# x = int(zbi['x']) / int('2') + int('50')
# y = int(zbi['y']) / int('2') + int('140')
t += 1
zb.append(zbi)
# print(zb)
zib = [(((zb[0]['x'])) / int('2') + int('50'), (zb[0]['y']) / int('2') + int('140')),
(((zb[1]['x'])) / int('2') + int('50'), (zb[1]['y']) / int('2') + int('140')),
(((zb[2]['x'])) / int('2') + int('50'), (zb[2]['y']) / int('2') + int('140'))]
# print('原来识别到的坐标',zib)
if (259, 368) < zib[0] < (439, 409): # 270< zb[0]['x'] < 420 and 375
# cde=zib[0]+zib[1]
zib.append(((zb[0]['x']) / int('2') - int('150'), (zb[0]['y']) / int('2') + int('150')))
# print('新坐标1',zib)
while i < len(answer):
if answer[i] not in xin:
# print('本道题识别到的答案与原答案不一样,为避免报错,随机选择一个选项')
zuobiao = dict(qq[-1])
zuobiao2= dict(qq[-2])
zuobiao3= dict(qq[-3])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
x1 = int(zuobiao2['x']) / int('2') + int('50')
y1 = int(zuobiao2['y']) / int('2') + int('140')
x2 = int(zuobiao3['x']) / int('2') + int('50')
y2 = int(zuobiao3['y']) / int('2') + int('140')
# # print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
time.sleep(0.5)
pyautogui.click(x1, y1)
time.sleep(0.5)
pyautogui.click(x2, y2)
# time.sleep(0.5)
time.sleep(0.5)
# i += 1
break
else:
p = xin.index(answer[i])
zuobiao = zib[p]
# print(zuobiao)
pyautogui.click(zuobiao)
time.sleep(0.5)
i += 1
break
# time.sleep(0.5)
elif (66, 368) < zib[0] < (210, 409) and (66, 434) < zib[1] < (210, 470):
zib.append(((zb[0]['x']) / int('2') + int('250'), (zb[0]['y']) / int('2') + int('150')))
# zib.append((zb[0]['x']/ int('2')+int('250'),zb[0]['y']/ int('2')+int('140')))
# print('新坐标2',zib)
while i < len(answer):
if answer[i] not in xin:
zuobiao = dict(qq[-1])
zuobiao2 = dict(qq[-2])
zuobiao3 = dict(qq[-3])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
x1 = int(zuobiao2['x']) / int('2') + int('50')
y1 = int(zuobiao2['y']) / int('2') + int('140')
x2 = int(zuobiao3['x']) / int('2') + int('50')
y2 = int(zuobiao3['y']) / int('2') + int('140')
# # print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
time.sleep(0.5)
pyautogui.click(x1, y1)
time.sleep(0.5)
pyautogui.click(x2, y2)
# time.sleep(0.5)
time.sleep(0.5)
# i += 1
break
else:
p = xin.index(answer[i])
zuobiao = zib[p]
# print(zuobiao)
pyautogui.click(zuobiao)
time.sleep(0.5)
i += 1
break
elif (66, 342) < zib[0] < (210, 409) and (259, 342) < zib[1] < (441, 426) and (259, 426) < zib[
2] < (441, 500):
# zib.append((zb[2]['x']/ int('2')-int('70'),zb[2]['y']/ int('2')-int('50')))
zib.append(((zb[0]['x']) / int('2') + int('50'), (zb[0]['y']) / int('2') + int('200')))
# print('新坐标3',zib)
while i < len(answer):
p = xin.index(answer[i])
zuobiao = zib[p]
# print(zuobiao)
pyautogui.click(zuobiao)
time.sleep(0.5)
i += 1
# time.sleep(0.5)
elif (66, 342) < zib[0] < (210, 469) and (259, 342) < zib[1] < (441, 469) and (50, 426) < zib[2] < (
210, 530):
# zib.append((zb[2]['x'] / int('2') - int('10'), zb[2]['y'] / int('2') - int('50')))
zib.append(((zb[2]['x']) / int('2') + int('250'), (zb[2]['y']) / int('2') + int('140')))
# print('新坐标4',zib)
while i < len(answer):
if answer[i] not in xin:
# print('本道题识别到的答案与原答案不一样,为避免报错,随机选择一个')
zuobiao = dict(qq[-2])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
# zuobiaoo=[(162,449),(347,449),(139,512),(347,512),(int(zuobiao['x']) / int('2') + int('50'),int(zuobiao['y']) / int('2') + int('140'))]
# print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
# i += 1
break
else:
p = xin.index(answer[i])
zuobiao = zib[p]
# print(zuobiao)
pyautogui.click(zuobiao)
time.sleep(0.5)
i += 1
break
else:
pyautogui.click(143,443)
time.sleep(0.2)
pyautogui.click(360,443)
time.sleep(0.2)
pyautogui.click(143,507)
time.sleep(0.2)
pyautogui.click(360,507)
time.sleep(0.2)
pyautogui.click(143,574)
time.sleep(0.2)
pyautogui.click(360,574)
break
else:
p = h.index(answer[i])
zuobiao = dict(qq[p])
zuobiao1=dict(qq[p+4])
x = int(zuobiao['x']) / int('2') + int('50')
y = int(zuobiao['y']) / int('2') + int('140')
x1=int(zuobiao1['x']) / int('2') + int('50')
y1=int(zuobiao1['y']) / int('2') + int('140')
# print(x)
# print(y)
# print(x, y)
pyautogui.click(x, y)
time.sleep(0.5)
pyautogui.click(x1, y1)
# i += 1
# time.sleep(0.5)
# print(1)
break
else:
x = int(qq[-2]['x']) / int('2') + int('50')
y = int(qq[-2]['y']) / int('2') + int('140')
pyautogui.click(x, y)
# time.sleep(0.5)
break
else:
time.sleep(2)
x = int(qq[-1]['x']) / int('2') + int('50')
y = int(qq[-1]['y']) / int('2') + int('140')
pyautogui.click(x,y)
# break
# pyautogui.click(240, 358)
# k = 0
# while k < 2:
# time.sleep(th)
# time.sleep(th)
# time.sleep(th)
time.sleep(float(thh))
# pyautogui.click(400, 1000)
pyautogui.click(int(fb1),int(fb2))
t3 = cv.getTickCount()
print("every topic time cost:%s s" % ((t3 - t1) / cv.getTickFrequency()))
continue
except:
if (h[2] >= u'\u4e00' and h[2]<=u'\u9fa5') and (h[3] >= u'\u4e00' and h[3]<=u'\u9fa5' ) :
if len(answer) <= 3:
zib = [((qq[-1]['x']) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('150')),
((qq[-2]['x']) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('145'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
# pyautogui.click(213,760)
time.sleep(0.5)
pyautogui.click(int(fb1),int(fb2))
t2 = cv.getTickCount()
print("every topic time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
# break
# continue
elif 3< len(answer) <5:
zib = [((qq[-1]['x']) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('150')),
((qq[-2]['x']) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('145')),
((qq[-3]['x']) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('150')),
((qq[-4]['x']) / int('2') + int('50'), (qq[-4]['y']) / int('2') + int('145')),
((qq[-5]['x']) / int('2') + int('50'), (qq[-5]['y']) / int('2') + int('150'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[2])
time.sleep(0.5)
pyautogui.click(zib[3])
time.sleep(0.5)
pyautogui.click(zib[4])
time.sleep(0.5)
# pyautogui.click(zib[5])
# time.sleep(0.5)
# pyautogui.click(zib[6])
pyautogui.click(int(fb1),int(fb2))
t2 = cv.getTickCount()
print("every topic time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
# continue
else:
zib = [((qq[-1]['x']) / int('2') + int('50'), (qq[-1]['y']) / int('2') + int('150')),
((qq[-2]['x']) / int('2') + int('50'), (qq[-2]['y']) / int('2') + int('145')),
((qq[-3]['x']) / int('2') + int('50'), (qq[-3]['y']) / int('2') + int('150')),
((qq[-4]['x']) / int('2') + int('50'), (qq[-4]['y']) / int('2') + int('145')),
((qq[-5]['x']) / int('2') + int('50'), (qq[-5]['y']) / int('2') + int('150')),
((qq[-6]['x']) / int('2') + int('50'), (qq[-6]['y']) / int('2') + int('145')),
((qq[-7]['x']) / int('2') + int('50'), (qq[-7]['y']) / int('2') + int('150'))]
pyautogui.click(zib[0])
time.sleep(0.5)
pyautogui.click(zib[1])
time.sleep(0.5)
pyautogui.click(zib[2])
time.sleep(0.5)
pyautogui.click(zib[3])
time.sleep(0.5)
pyautogui.click(zib[4])
time.sleep(0.5)
pyautogui.click(zib[5])
time.sleep(0.5)
pyautogui.click(zib[6])
time.sleep(0.5)
pyautogui.click(int(fb1), int(fb2))
t2 = cv.getTickCount()
print("every topic time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
# continue
else:
pyautogui.click(135, 371)
time.sleep(0.5)
pyautogui.click(344, 371)
time.sleep(0.5)
pyautogui.click(135, 443)
time.sleep(0.5)
pyautogui.click(344, 443)
time.sleep(0.5)
pyautogui.click(135, 504)
time.sleep(0.5)
pyautogui.click(344, 504)
time.sleep(0.5)
pyautogui.click(135, 570)
time.sleep(0.5)
pyautogui.click(344, 570)
time.sleep(0.5)
pyautogui.click(144, 631)
time.sleep(0.5)
pyautogui.click(344, 631)
pyautogui.click(int(fb1), int(fb2))
t2 = cv.getTickCount()
print("every topic time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))
continue
# break
# sys.exit(app.exec_())
# input("Entry the any key to exit")