-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto.py
More file actions
executable file
·173 lines (120 loc) · 4.75 KB
/
auto.py
File metadata and controls
executable file
·173 lines (120 loc) · 4.75 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/python3
# -*- coding: iso-8859-15 -*-
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 unidecode import unidecode
from datetime import datetime
from time import sleep
from time import time
import random
import sys
import os
current_dir = os.getcwd()
sys.path.append(os.path.abspath(current_dir))
import main
class element_has_no_empty_class(object):
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
# Finding the referenced element
element = self.locator
if "empty" in element.get_attribute("class"):
return False
else:
return element
for i in range(int(sys.argv[1])):
t0 = time()
try:
driver = webdriver.Firefox()
driver.get("https://term.ooo/")
WebDriverWait(driver, 10).until(
EC.title_is("Termo")
)
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
main.excluded = []
main.contains = {}
main.awnser = {0: '', 1: '', 2: '', 3: '', 4: ''}
main.exclusiveOne = []
main.TwoOrMore = []
row = 0
choice = 'vasco'
print(choice)
while (row < 6):
letters = []
positions = []
position = 0
webdriver.ActionChains(driver).send_keys(choice).perform()
webdriver.ActionChains(driver).send_keys(Keys.ENTER).perform()
while (position < 5):
line = driver.execute_script("""return document.querySelector('wc-board').shadowRoot.querySelector("wc-row[termo-row='{}']").
shadowRoot.querySelector("div[termo-pos='{}']")""".format(row, position))
WebDriverWait(driver, 10).until(
element_has_no_empty_class(line)
)
position += 1
if ("wrong" in line.get_attribute("class")):
color = 'black'
elif ("right" in line.get_attribute("class")):
color = 'green'
else:
color = 'yellow'
if (color == 'green'):
letters.append(unidecode((line.text)).lower())
positions.append(position)
elif (color == 'yellow'):
letters.append(unidecode((line.text)).lower())
positions.append(-abs(position))
else:
letters.append(unidecode((line.text)).lower())
positions.append(0)
# Check if the awnser is correctly
positives = 0
for i in positions:
if(i>0): positives += 1
if(positives == len(positions)): break
# Starts to use the 'main code'
main.InsertWord(letters, positions)
solution = []
for word in main.words:
if (main.checkExcluded(word) and main.checkContains(word) and main.checkExact(word) and main.checkExclusivelyOne(word) and main.checkTwoMore(word)):
solution.append(unidecode(word[0:5]))
print("Quantidade de possiveis respostas: {}\n".format(len(solution)))
choice = random.choice(solution)
print(choice)
row += 1
sleep(1)
#sleep(2)
now = datetime.now()
current_time = now.strftime("%H-%M-%S")
folder_name = now.strftime("%d-%m")
if(row == 6):
try:
os.mkdir(current_dir + "/Screenshots/Error/{}".format(folder_name))
except:
pass
finally:
driver.save_screenshot(current_dir + '/Screenshots/Error/{}/{}.png'.format(folder_name, current_time))
else:
try:
os.mkdir(current_dir + "/Screenshots/Success/{}".format(folder_name))
except:
pass
finally:
driver.save_screenshot(current_dir + '/Screenshots/Success/{}/{}.png'.format(folder_name, current_time))
driver.close()
print(time()-t0)
except:
now = datetime.now()
current_time = now.strftime("%H-%M-%S")
folder_name = now.strftime("%d-%m")
try:
os.mkdir(current_dir + "/Screenshots/Failure/{}".format(folder_name))
except:
pass
finally:
driver.save_screenshot(current_dir + '/Screenshots/Failure/{}/{}.png'.format(folder_name, current_time))
driver.close()
print(time()-t0)