-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleHighscore.py
227 lines (186 loc) · 7.74 KB
/
SimpleHighscore.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import pathlib
import customtkinter as ctk
import threading
import time
CHROMEDRIVER_PATH = r"C:\\Users\\anmel\\OneDrive\\Desktop\\chromedriver-win32\\chromedriver.exe"
WEBSITE_PATH = "https://www.whatbeatsrock.com"
DIR_PATH = pathlib.Path().resolve()
automate = True
app = ctk.CTk()
app.geometry("600x400")
app.title("Terminal")
output_textbox = ctk.CTkTextbox(app, width=600, height=350)
output_textbox.pack(pady=0, padx=5)
input_entry = ctk.CTkEntry(app, width=600, height=40, placeholder_text="Console: ")
input_entry.pack(pady=0, padx=5)
input_entry.bind("<Return>", lambda event: on_enter_press())
output_textbox.tag_config("info", foreground="black")
output_textbox.tag_config("success", foreground="green")
output_textbox.tag_config("correct", foreground="#00FF00")
output_textbox.tag_config("warning", foreground="orange")
output_textbox.tag_config("error", foreground="red")
output_textbox.tag_config("note", foreground="#2b55e2")
output_textbox.tag_config("note2", foreground="#b82be2")
def remove_duplicates(list):
clean_list = []
for i in list:
if i not in clean_list:
clean_list.append(i)
return clean_list
def on_enter_press():
user_input = user_input = input_entry.get().lower()
log_message(f"Captured user Input: '{user_input}'", tag="note")
if user_input == "quit":
quit_bool.set()
user_input_comit.set()
elif user_input == "start":
start_bool.set()
input_entry.delete(0, ctk.END)
else:
user_input_comit.set()
def log_message(msg, tag="info", end="\n"):
output_textbox.insert("end", f"{time.strftime("%H:%M:%S", time.localtime())}: " + msg + end, tag)
output_textbox.see("end")
def num_to_id(num):
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
id = ""
for i in str(num):
id += letters[int(i)]
return id
def main(id):
names = []
for i in range(100000, 133333):
names.append(f"A Robot named {num_to_id(i)} that plays Paper")
names.append(f"A Robot named {num_to_id(i)} that plays Scissor")
names.append(f"A Robobt named {num_to_id(i)} that plays Rock")
log_message("Input List Generated", tag="success")
service = Service(executable_path=CHROMEDRIVER_PATH)
driver = webdriver.Chrome(service=service)
log_message("Chrome Driver initialized", tag="success")
driver.get(WEBSITE_PATH)
log_message("Website loaded", tag="success")
log_message("To start the programm type 'start'", tag="note2")
while not start_bool.is_set():
time.sleep(0.5)
user_input_comit.clear()
input_entry.delete(0, ctk.END)
log_message("Starting to insert words", tag="warning")
prev_word = "Rock"
score = 0
for name in names:
if quit_bool.is_set():
log_message("Quitting Driver and Terminal ...", tag="warning")
time.sleep(1)
driver.quit()
app.quit()
pause = False
if user_input_comit.is_set():
user_input_comit.clear()
user_input = input_entry.get().lower()
input_entry.delete(0, ctk.END)
pause = False
if user_input == "pause":
pause = True
log_message(f"Pausing Script ...", tag="warning")
log_message(f"Score: {score}")
log_message(f"To continue the programm type 'continue'", tag="note2")
log_message(f"To quit the programm type 'quit'", tag="note2")
while pause:
while not user_input_comit.is_set():
time.sleep(0.5)
user_input_comit.clear()
user_input = input_entry.get().lower()
input_entry.delete(0, ctk.END)
if user_input == "continue":
log_message("Continuingt the script ...", tag="warning")
break
elif user_input == "quit":
log_message("Quitting Driver and Terminal ...", tag="warning")
time.sleep(1)
driver.quit()
app.quit()
input_field = driver.find_element(By.CSS_SELECTOR, ".pl-4.py-4.text-lg.border.border-1-black")
input_field.clear()
input_field.send_keys(name)
input_field.send_keys(Keys.RETURN)
alert = None
try:
time.sleep(0.5)
alert = driver.switch_to.alert
alert_text = alert.text
alert.accept()
except NoAlertPresentException:
pass
while alert:
user_input_comit.clear()
log_message(f"Alert: {alert_text}", tag="error")
if alert_text == "rate limit exceeded! slow down or dm us on discord/twitter" and automate:
log_message(f"Waiting 1 minute before trying to continue programm", tag="warning")
time.sleep(60)
log_message(f"Continuing the programm", tag="warning")
break
else:
log_message(f"Score: {score}")
log_message(f"To try to continue the programm type 'continue'", tag="note2")
log_message(f"To quit the programm type 'quit'", tag="note2")
while True:
while not user_input_comit.is_set():
time.sleep(0.5)
user_input = input_entry.get().lower()
input_entry.delete(0, ctk.END)
if user_input == "continue":
log_message("Continuing the programm", tag="warning")
input_field.send_keys(Keys.RETURN)
break
elif user_input == "quit":
log_message("Quitting Driver and Terminal ...", tag="warning")
time.sleep(1)
driver.quit()
app.quit()
try:
time.sleep(0.5)
alert = driver.switch_to.alert
alert_text = alert.text
alert.accept()
except NoAlertPresentException:
break
correct = None
while True:
try:
button_field = driver.find_element(By.CSS_SELECTOR, ".py-4.px-8.border.border-1-black.text-lg")
correct = True
break
except selenium.common.exceptions.NoSuchElementException:
pass
try:
button_field = driver.find_element(By.CSS_SELECTOR, ".p-2.px-4.border.border-1-black.text-lg")
correct = False
break
except selenium.common.exceptions.NoSuchElementException:
pass
time.sleep(0.5)
if correct:
prev_word = name
score += 1
button_field.send_keys(Keys.RETURN)
else:
log_message(f"{name} does not beat {prev_word}", tag="error")
score = driver.find_element(By.CSS_SELECTOR, "p.text-gray-500").text.split(": ")[1]
log_message(f"Score: {score}")
input()
driver.quit()
log_message("Ran out of Words", tag="warning")
log_message(f"Score: {score}")
user_input_comit = threading.Event()
quit_bool = threading.Event()
start_bool = threading.Event()
thread = threading.Thread(target=main, args=(1,), daemon=True)
thread.start()
app.mainloop()