-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxtraMathbot.py
More file actions
125 lines (89 loc) · 3.65 KB
/
Copy pathxtraMathbot.py
File metadata and controls
125 lines (89 loc) · 3.65 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support import expected_conditions as expect
from selenium.webdriver.common.action_chains import ActionChains
from pynput.keyboard import Key, Controller
import pyautogui
from PIL import Image
import time
import pytesseract
import cv2
#note that u have to run program 3 or 4 times after it is done and it shows ur progress and report on how many questions you got write and wrong exit out of it after and run code until it says u beat it
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://xtramath.org/#/signin/student_other")
driver.maximize_window()
time.sleep(5)
elem = WebDriverWait(driver, 120, 1).until(
expect.visibility_of_element_located(
(By.XPATH, "//input[@placeholder='Parent or Teacher']")))
elem.click()
elem.send_keys("omp091216@gmail.com")
text = WebDriverWait(driver, 120, 1).until(
expect.visibility_of_element_located(
(By.XPATH, "(//input[@name='displayName'])[2]")))
text.click()
text.send_keys("test")
pin = WebDriverWait(driver, 120, 1).until(
expect.visibility_of_element_located(
(By.XPATH, "(//input[@name='pin'])[3]")))
pin.click()
pin.send_keys("6802")
time.sleep(3)
pin.send_keys(Keys.RETURN)
time.sleep(2)
keyboard = Controller()
for i in range(2):
time.sleep(2)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(4)
for i in range(200):
time.sleep(0.48)
screenshot = pyautogui.screenshot(region=(700,320,400,160))
screenshot.save(r'C:\Users\omp16\Documents\Python Projects\XtraMath\topno.png')
# this is screenshot number 1 (top No.)
pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
img = cv2.imread(r'C:\Users\omp16\Documents\Python Projects\XtraMath\topno.png')
img = cv2.resize(img,(0,0),fx=2,fy=2)
img = cv2.GaussianBlur(img,(11,11),0)
img = cv2.medianBlur(img,9)
ocr1 = pytesseract.image_to_string(img, lang='eng', config='--psm 6-c tessedit_char_whitelist=0123456789')
print(ocr1)
ocr1_split = ocr1.split()
print(ocr1_split)
ocr1_string = ocr1_split[0]
if ocr1_string == 'O':
ocr1_string = '0'
print(ocr1_string)
ocr1 = int(ocr1_string)
#IMAGE 2
screenshot = pyautogui.screenshot(region=(800,465,400,180))
screenshot.save(r'C:\Users\omp16\Documents\Python Projects\XtraMath\bottomno.png')
# this is screenshot number 2 (bottom No.)
pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
img2 = cv2.imread(r'C:\Users\omp16\Documents\Python Projects\XtraMath\bottomno.png')
img2 = cv2.resize(img2,(0,0),fx=2,fy=2)
img2 = cv2.GaussianBlur(img2,(11,11),0)
img2 = cv2.medianBlur(img2,9)
img2 = Image.fromarray(img2)
ocr2 = pytesseract.image_to_string(img2, lang='eng', config='--psm 8-c tessedit_char_whitelist=0123456789')
if ocr2 != '+5\n':
ocr2 = pytesseract.image_to_string(img2, lang='eng', config='--psm 7-c tessedit_char_whitelist=0123456789')
ocr2.strip(' +')
else:
ocr2 = '5'
ocr2 = ocr2.strip(' +')
ocr2_split = ocr2.split()
ocr2_string = ocr2_split[0]
if ocr2_string == 'O':
ocr2_string = '0'
if ocr2_string == 'f':
ocr2_string = '7'
ocr2 = int(ocr2_string)
result = ocr1 + ocr2
new_result = str(result)
keyboard.type(new_result)