-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve.py
86 lines (79 loc) · 2.81 KB
/
solve.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
import selenium
import time
import sys
import argparse
import word_proc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# argparse stuff
parser = argparse.ArgumentParser()
parser.add_argument(
"--browser",
help="Browser used to solve spellingbee, default is firefox",
default="firefox",
)
parser.add_argument(
"-l", "--login", action="store_true", help="use to manually log in to NYT"
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="print words that are being tried"
)
parser.add_argument(
"-S",
"--no_solve",
action="store_true",
help="do not solve, only list words in terminal",
)
args = parser.parse_args()
# validate arguments
if args.browser == "firefox":
driver = selenium.webdriver.Firefox()
elif args.browser == "chrome":
driver = selenium.webdriver.Chrome()
else:
print(f"unsupported browser called: {args.browser}")
print(f"contact me at github or open an issue to get {args.browser} support")
sys.exit(1)
if args.login: # loggin to NYT
driver.get(
"https://myaccount.nytimes.com/auth/enter-email?redirect_uri=https%3A%2F%2Fwww.nytimes.com%2Fpuzzles%2Fspelling-bee&response_type=cookie&client_id=games&application=crosswords&asset=navigation-bar"
)
wait = WebDriverWait(driver, 2_000)
wait.until(EC.url_to_be("https://www.nytimes.com/?login=email&auth=login-email"))
url = "https://www.nytimes.com/puzzles/spelling-bee"
driver.get(url)
plat_btn = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//button[text() ='Play']"))
)
driver.execute_script("arguments[0].click();", plat_btn)
middle_letter = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(
(By.XPATH, "//*[@class='cell-letter' or @class='center']")
)
)
middle_letter = middle_letter.get_attribute("innerHTML")
good_letters, btns = word_proc.get_good_letters_and_buttons(driver)
bad_letters = word_proc.get_bad_letters(good_letters)
# get list of english dictionary words
words = word_proc.get_words()
good_words = word_proc.get_good_words(bad_letters, words, middle_letter)
if args.no_solve:
print(good_words)
sys.exit(0)
if args.verbose:
print(good_words)
"""
element = driver.find_element(By.XPATH,"//div[@class='purr-blocker-card pz-hide-games-app pz-hide-newsreader']")
driver.execute_script("arguments[0].style.visibility='hidden'", element)
"""
# find enter button
enter_button = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.CLASS_NAME, "hive-action__submit"))
)
for word in good_words:
for char in word:
btns[char].click()
time.sleep(1)
enter_button.click()
driver.execute_script("arguments[0].click();", enter_button)