博客並沒有其他網站的號,未經允許不得私自轉發
博客太忙了,不想在繼續維護了,代碼開源
需要安裝的庫有
hashlib,base64,pykeyboard,pyautogui,numpy,opencv,json,time,requests等
本代碼的ocr文字識別基於訊飛,識別率比百度好,所以改用訊飛,
與前面的那版相比,可以說前面那版放棄是正確的,百度太摳了,每個月免費500,訊飛註冊就送10w,所以用這個了,具體怎麼用,看代碼把
需要配合fiddler,前面的爬取那塊單詞是大佬提供的
fiddler要改的地方
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<zb[0]['y']<400 :
# 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")