-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnitro.py
109 lines (109 loc) · 4.03 KB
/
nitro.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from autocorrect import spell
try:
from PIL import Image
except ImportError:
import Image
import pyautogui as pg
pg.FAILSAFE = False
import pytesseract
import random
from autocorrect import spell
import string
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
import cv2
import mss.tools as mt
from mss import mss
def correct(queue):
queue.translate(str.maketrans('', '', string.punctuation))
str_list = queue.split()
result_list = []
for word in str_list:
sympos = []
if (word.translate(str.maketrans('', '', string.punctuation)) == word):
result_list.append(word)
else:
_word = list(word)
for symbol in string.punctuation:
for char in range(len(_word)):
if _word[char] == symbol:
sympos.append([char, symbol])
adj = 0
for item in sympos:
_word.pop(item[0]-adj)
adj+=1
_word = list(spell(''.join(_word)))
for item in sympos:
_word.insert(item[0],item[1])
result_list.append("".join(_word))
queue = " ".join(result_list)
queue+=",."
#queue+=random.choice(string.ascii_letters)
#queue+=random.choice(string.ascii_letters)
return queue
def do_ocr(filename):
return((pytesseract.image_to_string(Image.open(filename))))
def screenshot(filename):
with mss() as sct:
screen = sct.shot(output=filename)
return(screen)
print("[Debug] Starting OCR Racer")
import time
#time.sleep(2)
end = False
refresh = ['%','%','%']
while True:
pg.scroll(1000)
screenshot("screen.png")
imageObject = Image.open("screen.png")
imageObject.crop((700,840,1210,868)).save('line.png') # THESE VALUES MUST CHANGE
imageObject.crop((700,410,1200,470)).save('race.png')
if(open("race.png","rb").read() == open("RESULTS.png","rb").read()):
print('[Debug] Race End Detected')
pg.press("enter")
time.sleep(2)
pg.scroll(1000)
while True:
screenshot("screen.png")
imageObject = Image.open("screen.png")
imageObject.crop((700,840,1210,868)).save('waiting.png') # THESE VALUES MUST CHANGE
if (open("waiting.png","rb").read() != open("wait.png","rb").read()):
break
imageObject.crop((700,840,1210,868)).save('line.png') # THESE VALUES MUST CHANGE
queue = do_ocr("line.png")
#print(queue)
queue = queue.replace('’',"'")
refresh.pop(0)
refresh.append(queue)
print(refresh)
queue = correct(queue)
queue = queue.replace('’',"'")
#print(queue)
pg.typewrite(queue, interval=random.uniform(0.03, 0.04))
if (random.randint(1,4)==3):
pg.typewrite(random.choice(string.ascii_letters)+random.choice(string.ascii_letters))
pg.press('space')
pg.scroll(1000)
#time.sleep(0.2)
if (len(set(refresh))==1 and (refresh[0] != 'Please wait. Typing content will')):
print("[Debug] Failsafe Triggered")
print(refresh)
pg.press('f5')
time.sleep(5)
refresh = ['%','%','%']
if(refresh == ['Please wait. Typing content will', 'Please wait. Typing content will', 'Please wait. Typing content will']):
screenshot("screen.png")
#imageObject = Image.open("screen.png")
#imageObject.crop((750,300,1150,520)).save('isdq.png')
pg.click(x=1017, y=482)
time.sleep(5)
#if (open("isdq.png","rb").read() == open("dq.png","rb").read()):
# print('[Debug] Disqualified (in another race)')
# pg.press('f5')
# time.sleep(3)
screenshot("screen.png")
imageObject = Image.open("screen.png")
imageObject.crop((750,300,1150,450)).save('inactive.png')
if (open("inactive.png","rb").read() == open("ia.png","rb").read()):
print('[Debug] Disqualified (inactivity)')
pg.press('f5')
time.sleep(3)