-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
75 lines (56 loc) · 2.1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
import json
import time
import re
import sys
from PIL import ImageChops
from process.ScreenCapture import ScreenCapture
from process.OCR import OCR
from process.Query import Query
from process.Click import Click
cc = Click(0, 40)
END_WORDS_DICT = {
"VICTORY": True
}
def isSame(imgA, imgB):
if imgA is None or imgB is None:
return False
diff = ImageChops.difference(imgA.convert('RGB'), imgB.convert('RGB'))
if diff.getbbox():
return False
return True
def getOCRConfig():
with open("./config.json", "r", encoding="utf-8") as fp:
return json.load(fp)
if __name__ == "__main__":
config = getOCRConfig()
sc = ScreenCapture()
ocr = OCR(config["APP_ID"], config["API_KEY"], config["SECRET_KEY"])
query = Query()
quesImg, answImg = None, None
tmpQuesText = ''
while True:
tmpQuesImg, tmpAnswImg, appImg = sc.run()
# print(tmpQuesImg)
# print(tmpAnswImg)
if not isSame(quesImg, tmpQuesImg):
quesImg, answImg, appImg = tmpQuesImg, tmpAnswImg, appImg
ques, answ = ocr.run(quesImg, answImg)
# 如果匹配victory|defeat退出程序
if re.search('victory|defeat|defert|自动匹配|排行榜|看广告', "".join(answ), flags=re.I):
sys.exit()
if (len(ques) > 0 and (tmpQuesText != ques)):
tmpQuesText = ques
freq, rightAnswer, hint = query.run(ques, answ)
if(rightAnswer is not None):
print("问题: {}".format(ques))
print("\033[1;47;32m正确答案: {}\033[0m".format(rightAnswer))
freqText = ''
for index in range(len(freq)):
freqText += (answ[index] + ' :' + str(round(100 * freq[index], 1)) + '% ')
print('概率: {}'.format(freqText))
print('依据: {}'.format(hint))
cc.run(appImg, answ, rightAnswer)
print('-----------------')
print()
time.sleep(0.1)