Skip to content

Commit 40247c7

Browse files
committed
flake8 linting
1 parent b13851a commit 40247c7

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

wordle_solver/wordle_solver.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# https://www.wordunscrambler.net/word-list/wordle-word-list for the list of words
1+
# https://www.wordunscrambler.net/word-list/wordle-word-list
2+
# for the list of words
23

34
from selenium import webdriver
45
from selenium.webdriver.common.by import By
@@ -21,7 +22,9 @@ def __init__(self):
2122
self.present_letters = set([])
2223
self.absent_letters = set([])
2324
self.word = [''] * 5
24-
self.word_to_try = "slate" # Creators recommend “Slate” as starting word
25+
26+
# Creators recommend “Slate” as starting word
27+
self.word_to_try = "slate"
2528

2629

2730
# Function that is called by the KeyboardListener
@@ -33,7 +36,8 @@ def on_release(key):
3336

3437
# Get the status of the letters in the wordle
3538
def get_row_results(game_row):
36-
tiles = game_row.find_elements(By.XPATH, ".//*[contains(@class, 'Tile-module_tile__')]")
39+
tiles = game_row.find_elements(
40+
By.XPATH, ".//*[contains(@class, 'Tile-module_tile__')]")
3741
row_results = []
3842
res_to_int = {
3943
"correct": 1,
@@ -57,7 +61,8 @@ def enter_word(word):
5761
time.sleep(2)
5862

5963

60-
# Check word length, used in get_list_of_words() if the source list contains words with different length
64+
# Check word length, used in get_list_of_words()
65+
# if the source list contains words with different length
6166
def check_word_length(word):
6267
if len(word) != 5:
6368
return False
@@ -73,7 +78,8 @@ def check_letter_in_word(letter, word):
7378
return False
7479

7580

76-
# Check if the letter in the finder object is the same as the letter in the possible answer
81+
# Check if the letter in the finder object
82+
# is the same as the letter in the possible answer
7783
def check_match(finder_word_letter, possible_word_letter):
7884
if finder_word_letter == possible_word_letter:
7985
return True
@@ -98,43 +104,58 @@ def solving_algorithm(res, finder):
98104

99105
# Compare the word with the results of the wordle
100106
for letter in range(len(word)):
101-
if res[letter] == 1: # Case when the status of the letter is "correct"
107+
# Case when the status of the letter is "correct"
108+
if res[letter] == 1:
102109
print(f"Letter {word[letter]} is correct")
103110
finder.word[letter] = word[letter]
104111
print(finder.word)
105112
if word[letter] in finder.absent_letters:
106113
finder.absent_letters.remove(word[letter])
107114

108-
elif res[letter] == 0: # Case when the status of the letter is "present" (present but at the wrong position)
115+
# Case when the status of the letter is "present"
116+
# (present but at the wrong position)
117+
elif res[letter] == 0:
109118
print(f"Letter {word[letter]} is present")
110119
finder.present_letters.add(word[letter])
111-
# We keep all the words that don't match the pattern of the word entered
120+
# We keep all the words that don't match
121+
# the pattern of the word entered
112122
finder.possible_words = list(
113-
filter(lambda x_word: not check_match(word[letter], x_word[letter]), finder.possible_words))
123+
filter(lambda x_word:
124+
not check_match(word[letter], x_word[letter]),
125+
finder.possible_words))
114126

115127
else: # Case when the status of the letter is "absent"
116128
print(f"Letter {word[letter]} is absent")
117129
if word[letter] not in finder.present_letters:
118130
finder.absent_letters.add(word[letter])
119131

120-
# We keep all the words that don't match the pattern of the word entered
132+
# We keep all the words that don't match
133+
# the pattern of the word entered
121134
finder.possible_words = list(
122-
filter(lambda x_word: not check_match(word[letter], x_word[letter]), finder.possible_words))
135+
filter(lambda x_word:
136+
not check_match(word[letter], x_word[letter]),
137+
finder.possible_words))
123138

124139
print("\n")
125140
print("Updating list of possible words ...")
126141

127142
# Update list of words
128143
for absent in finder.absent_letters:
129144
finder.possible_words = list(
130-
filter(lambda x_word: not check_letter_in_word(absent, x_word), finder.possible_words))
145+
filter(lambda x_word:
146+
not check_letter_in_word(absent, x_word),
147+
finder.possible_words))
131148
for present in finder.present_letters:
132149
finder.possible_words = list(
133-
filter(lambda x_word: check_letter_in_word(present, x_word), finder.possible_words))
150+
filter(lambda x_word:
151+
check_letter_in_word(present, x_word),
152+
finder.possible_words))
134153
for i in range(len(finder.word)):
135154
if finder.word[i] != "":
136155
finder.possible_words = list(
137-
filter(lambda x_word: check_match(x_word[i], finder.word[i]), finder.possible_words))
156+
filter(lambda x_word:
157+
check_match(x_word[i], finder.word[i]),
158+
finder.possible_words))
138159

139160
# Update the next word to try
140161
finder.word_to_try = finder.possible_words[0]
@@ -149,7 +170,8 @@ def solving_algorithm(res, finder):
149170

150171
def main():
151172
# Start the browser
152-
browser = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
173+
browser = webdriver.Firefox(
174+
service=FirefoxService(GeckoDriverManager().install()))
153175
browser.get("https://www.nytimes.com/games/wordle/index.html")
154176

155177
# Create the finder object (cf. class Finder)
@@ -162,12 +184,14 @@ def main():
162184
print("Starting program\n")
163185
listener.join()
164186

165-
# With "suppress=True", duplicate key presses are not sent to the application
166-
# but for some reason I need to add a delay for the first input to be sent.
187+
# With "suppress=True", duplicate key presses are not sent
188+
# to the application but for some reason I need to add a delay
189+
# for the first input to be sent.
167190
time.sleep(1)
168191

169192
# Get the game rows
170-
game_rows = browser.find_elements(By.XPATH, "//*[contains(@class, 'Row-module_row__')]")
193+
game_rows = browser.find_elements(
194+
By.XPATH, "//*[contains(@class, 'Row-module_row__')]")
171195

172196
# Enter words until the game is over or the wordle is solved
173197
for i in range(guesses_left, 0, -1):

0 commit comments

Comments
 (0)