Skip to content

Commit 980016c

Browse files
committed
Code Improvements
1 parent 8200e9c commit 980016c

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

wordle_solver/wordle_solver.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,23 @@
1515

1616
# Check word length
1717
def check_word_length(word):
18-
if len(word) != 6:
18+
if len(word) != 5:
1919
return False
2020
else:
2121
return True
2222

2323

24-
list_of_words = open("words_alpha.txt", "r").read().splitlines()
24+
list_of_words = open("words_alpha.txt", "r").read().strip().splitlines()
2525
list_of_words = list(filter(check_word_length, list_of_words))
2626

2727

2828
def on_release(key):
29+
# Start button
2930
if key == keyboard.Key.esc:
3031
return False # stop listener
3132

3233

33-
def get_wordle_evaluation(game_row, browser):
34+
def get_row_results(game_row):
3435
tiles = game_row.find_elements(By.CLASS_NAME, "Tile-module_tile__3ayIZ")
3536
evaluation = []
3637
eval_to_int = {
@@ -46,8 +47,15 @@ def get_wordle_evaluation(game_row, browser):
4647
return tuple(evaluation)
4748

4849

50+
def enter_word(word):
51+
keyboard_controller = keyboard.Controller()
52+
keyboard_controller.type(word)
53+
keyboard_controller.tap(keyboard.Key.enter)
54+
time.sleep(2)
55+
56+
4957
def main():
50-
start_button = 'esc'
58+
# Start the browser
5159
browser = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
5260
browser.get("https://www.nytimes.com/games/wordle/index.html")
5361

@@ -56,26 +64,18 @@ def main():
5664
listener.join()
5765
print("Starting")
5866

59-
first_string = "moron"
60-
keyboard_controller = keyboard.Controller()
61-
keyboard_controller.type(first_string)
62-
keyboard_controller.tap(keyboard.Key.enter)
63-
64-
time.sleep(2)
65-
67+
# Get the game rows
6668
game_rows = browser.find_elements(By.CLASS_NAME, 'Row-module_row__dEHfN')
67-
# print("Game rows: ", len(game_rows))
68-
get_wordle_evaluation(game_rows[0], browser)
6969

70-
time.sleep(1)
70+
first_string = "tests"
71+
enter_word(first_string)
72+
get_row_results(game_rows[0])
7173

72-
second_string = "tests"
73-
keyboard_controller.type(second_string)
74-
keyboard_controller.tap(keyboard.Key.enter)
75-
76-
time.sleep(2)
74+
time.sleep(1)
7775

78-
get_wordle_evaluation(game_rows[1], browser)
76+
second_string = "trees"
77+
enter_word(second_string)
78+
get_row_results(game_rows[1])
7979

8080

8181
#From the basic list of words, return all the words with 5 characters.

0 commit comments

Comments
 (0)