Skip to content

Documentation

Main function that handles creating an instance and solving wordle.

solve(first_guess='')

Solve the wordle by selecting random 'best guesses'.

Args:
    first_guess (str, optional):
        The first guess the wordle solver will use.
        If blank, will just pick a random word. Defaults to "".

Raises:
    ValueError:
        Will raise a ValueError if provided an invalid first guess.
Source code in src/wordle_bot/__main__.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def solve(first_guess: str = "") -> None:
    """
    Solve the wordle by selecting random 'best guesses'.

        Args:
            first_guess (str, optional):
                The first guess the wordle solver will use.
                If blank, will just pick a random word. Defaults to "".

        Raises:
            ValueError:
                Will raise a ValueError if provided an invalid first guess.

    """
    # Solve wordle
    for _ in range(5):  # Attempts to solve wordle 5 times in case it fails
        wordle = Wordle(headless=True)
        solved = wordle.solve(first_guess=first_guess)
        if solved is True:
            break

    if os.getenv("GITHUB_WORKSPACE"):
        output_file(wordle)

Wordle Module, connects to and plays Wordle

Wordle

Handles all the logic for connecting to NYT website and playing Wordle.

Raises:

Type Description
ValueError

Will raise a value error if you provide an invalid first guess when using Wordle.solve().

Parameters:

Name Type Description Default
headless bool

Will run the selenium browser in headless mode. You will still be able to see what is going on since it will build a dynamic table in the console. Defaults to False.

False
Source code in src/wordle_bot/wordle.py
 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
class Wordle:
    """
    Handles all the logic for connecting to NYT website and playing Wordle.

    Raises:
        ValueError:
            Will raise a value error if you provide an
            invalid first guess when using Wordle.solve().

    Args:
        headless (bool, optional):
            Will run the selenium browser in headless mode.
            You will still be able to see what is going on since
            it will build a dynamic table in the console.
            Defaults to False.
    """

    NYT_WEBSITE = "https://www.nytimes.com/games/wordle/index.html"
    PLAY_BUTTON_CLASS = "Welcome-module_button__ZG0Zh"
    CLOSE_POPUP_CLASS = "Modal-module_closeIconButton__y9b6c"
    ROW_CLASS = "Row-module_row__pwpBq"
    TILE_CLASS = "Tile-module_tile__UWEHN"
    CSS_EMPTY = ".Tile-module_tile__UWEHN[data-state=empty]"
    CSS_ABSENT = ".Tile-module_tile__UWEHN[data-state=absent]"
    CSS_CORRECT = ".Tile-module_tile__UWEHN[data-state=correct]"
    CSS_PRESENT = ".Tile-module_tile__UWEHN[data-state=present]"
    FIVE_LETTER_WORDS_ABSOLUTE_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)),
        "five_letter_words.json",
    )

    def __init__(self, headless: bool = False) -> None:
        self.console = Console()
        with self.console.status("Setting up Wordle..."):
            try:
                response = requests.get("https://raw.githubusercontent.com/Jampamane/wordle_bot/refs/heads/main/five_letter_words.json")
                response.raise_for_status()
                self.five_letter_words = response.json()
            except requests.RequestException as e:
                print("Error fetching data:", e)
            except ValueError as e:
                print("Error decoding JSON:", e)

            self.potential_words = self.five_letter_words
            self.potential_letters = [
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
                "g",
                "h",
                "i",
                "j",
                "k",
                "l",
                "m",
                "n",
                "o",
                "p",
                "q",
                "r",
                "s",
                "t",
                "u",
                "v",
                "w",
                "x",
                "y",
                "z",
            ]
            self.style_dict = {
                "absent": "grey53",
                "present": "yellow bold",
                "correct": "green bold",
                "tbd": "red",
            }
            self.wordle = {
                "letters": {
                    1: {"correct": "", "incorrect": []},
                    2: {"correct": "", "incorrect": []},
                    3: {"correct": "", "incorrect": []},
                    4: {"correct": "", "incorrect": []},
                    5: {"correct": "", "incorrect": []},
                },
                "absent_letters": [],
                "present_letters": [],
                "guess": {
                    1: {"word": "", "letters": []},
                    2: {"word": "", "letters": []},
                    3: {"word": "", "letters": []},
                    4: {"word": "", "letters": []},
                    5: {"word": "", "letters": []},
                    6: {"word": "", "letters": []},
                },
            }
            options = Options()
            options.add_experimental_option("excludeSwitches", ["enable-logging"])
            options.add_argument("--log-level=3")
            options.add_argument("--no-sandbox")  # Bypass OS security model
            options.add_argument("--disable-dev-shm-usage")  # Overcome limited resource issues
            options.add_argument("--disable-gpu")  # Applicable for Windows/Linux GUI environments
            options.add_argument("--remote-debugging-port=9222")  # Debugging port for ChromeDriver
            options.add_argument("--disable-software-rasterizer")  # Avoid GPU rendering issues
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-logging")
            options.add_argument("--disable-popup-blocking")
            if headless is True:
                options.add_argument("--headless")
            options.add_argument("--ignore-certificate-errors")
            options.add_argument("--ignore-ssl-errors")

            try:
                self.browser = Chrome(options=options)
            except SessionNotCreatedException as e:
                self.console.print("Selenium web browser failed to start!", style="red")
                self.console.print("You might be missing some dependencies.", style="red")
                self.console.print("Selenium error: SessionNotCreatedException", style="yellow")
                exit(3)

            self.action_chains = ActionChains(self.browser)

            self.browser.get(self.NYT_WEBSITE)

            # ----------------------------------------------------------------------------------
            # NEW YORK TIMES "WE'VE UPDATED OUR TERMS OF SERVICE" BUTTON
            try:
                WebDriverWait(self.browser, 10).until(
                    EC.presence_of_element_located(
                        (By.CLASS_NAME, "purr-blocker-card__button")
                    )
                )
                self.browser.find_element(
                    By.CLASS_NAME, "purr-blocker-card__button"
                ).click()
            except TimeoutException:
                pass
            # -----------------------------------------------------------------------------------

            WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, self.PLAY_BUTTON_CLASS))
            )
            play = self.browser.find_elements(By.CLASS_NAME, self.PLAY_BUTTON_CLASS)[-1]
            play.click()
            time.sleep(1)
            self.action_chains.send_keys(Keys.ESCAPE).perform()
            time.sleep(1)

            last_row = self.browser.find_elements(By.CLASS_NAME, self.ROW_CLASS)[5]
            self.action_chains.scroll_to_element(last_row).perform()

    @property
    def wordle_today(self) -> str:
        """
        Grabs today's wordle from the Wordle Class's wordle dictionary.
        Only works if wordle has been solved.

        Returns:
            str: Today's wordle.
        """
        return str(
            self.wordle["letters"][1]["correct"]
            + self.wordle["letters"][2]["correct"]
            + self.wordle["letters"][3]["correct"]
            + self.wordle["letters"][4]["correct"]
            + self.wordle["letters"][5]["correct"]
        )

    def build_layout(self, guess="", style="yellow") -> Layout:
        """
        Dynamically build the layout in the console so
        the user can see how the wordle is being solved.

        Args:
            guess (str, optional):
                The 5 letter word that is being guessed. Defaults to "".
            style (str, optional):
                The color that the guess will be displayed as. Defaults to "yellow".

        Returns:
            Layout: Layout object for displaying wordle.
        """

        print_guess = False
        table = Table(title="Wordle", show_header=False)
        table.add_column("Guess", width=5, justify="center")
        table.add_column("1", width=1, justify="center")
        table.add_column("2", width=1, justify="center")
        table.add_column("3", width=1, justify="center")
        table.add_column("4", width=1, justify="center")
        table.add_column("5", width=1, justify="center")
        for x in range(1, 7):
            if self.wordle["guess"][x]["letters"]:
                table.add_row(
                    self.wordle["guess"][x]["word"].capitalize(),
                    f"[{self.wordle['guess'][x]['letters'][0][1]}]{self.wordle['guess'][x]['letters'][0][0]}",
                    f"[{self.wordle['guess'][x]['letters'][1][1]}]{self.wordle['guess'][x]['letters'][1][0]}",
                    f"[{self.wordle['guess'][x]['letters'][2][1]}]{self.wordle['guess'][x]['letters'][2][0]}",
                    f"[{self.wordle['guess'][x]['letters'][3][1]}]{self.wordle['guess'][x]['letters'][3][0]}",
                    f"[{self.wordle['guess'][x]['letters'][4][1]}]{self.wordle['guess'][x]['letters'][4][0]}",
                )
                table.add_section()
            elif not guess:
                table.add_row(str(x), style="cyan")
                table.add_section()
            elif print_guess is False:
                print_guess = True
                table.add_row(guess.capitalize(), style=style)
                table.add_section()
            else:
                table.add_row(str(x), style="cyan")
                table.add_section()

        letters = Table(show_header=False, show_lines=False, show_edge=False)
        letters.add_row(
            f"Total potential words: [cyan bold]{len(self.potential_words.keys())}"
        )
        words = Table(show_header=False, show_lines=False, show_edge=False)
        words.add_row(str(self.potential_letters))
        words.add_section()
        words.add_row(str(list(self.potential_words.keys())))

        layout = Layout()
        layout.split_row(Layout(name="table"), Layout(name="info"))
        layout["info"].split_column(Layout(name="letters"), Layout(name="words"))
        layout["table"].size = 33
        layout["letters"].size = 3
        layout["table"].update(Panel(table))
        layout["letters"].update(Panel(letters))
        layout["words"].update(Panel(words))
        return layout

    def _submit_guess(self, guess: str, row_number: int) -> bool:
        """Submits the guess to NYT Wordle.

        Args:
            guess (str):
                Guess to submit.
            row_number (int):
                Row number the guess is being submitted to.
                Used for validating if the guess was successful or not.

        Returns:
            bool: True or False based on if guess was successfully submitted.
        """
        for letter in guess:
            self.action_chains.send_keys(letter).perform()
            time.sleep(0.1)
        self.action_chains.send_keys(Keys.ENTER).perform()
        time.sleep(2.5)

        row = self.browser.find_elements(By.CLASS_NAME, self.ROW_CLASS)[row_number - 1]
        tiles = row.find_elements(By.CLASS_NAME, self.TILE_CLASS)
        for letter in tiles:
            letter_check = letter.get_attribute("data-state")
            if letter_check == "tbd":
                return False
        return True

    def _is_letter_duplicate(self, letter: str, word: str) -> bool:
        """Checks if a given letter shows up more than once in a word.

        Args:
            letter (str): Letter to check for duplicate.
            word (str): Word to check letter duplicate.

        Returns:
            bool: True if duplicate, False if otherwise.
        """
        count = 0
        for word_letter in word:
            if word_letter == letter:
                count += 1
        if count > 1:
            return True
        return False

    def _totally_absent(self, row_number: int, letter: str) -> bool:
        row = self.browser.find_elements(By.CLASS_NAME, self.ROW_CLASS)[row_number - 1]
        tiles = row.find_elements(By.CLASS_NAME, self.TILE_CLASS)
        for tile_letter in tiles:
            if tile_letter.text.lower() == letter:
                if tile_letter.get_attribute("data-state") != "absent":
                    return False
        return True

    def _update_wordle(self, row_number: int, word: str) -> None:
        self.wordle["guess"][row_number]["word"] = word
        row = self.browser.find_elements(By.CLASS_NAME, self.ROW_CLASS)[row_number - 1]
        tiles = row.find_elements(By.CLASS_NAME, self.TILE_CLASS)
        for indx, letter in enumerate(tiles, start=1):
            letter_check = letter.get_attribute("data-state")
            if letter_check == "absent":
                if (
                    self._is_letter_duplicate(letter=letter.text.lower(), word=word)
                    is True
                ):
                    if (
                        self._totally_absent(
                            row_number=row_number, letter=letter.text.lower()
                        )
                        is False
                    ):
                        self.wordle["letters"][indx]["incorrect"].append(
                            letter.text.lower()
                        )
                    else:
                        self.wordle["absent_letters"].append(letter.text.lower())
                else:
                    self.wordle["absent_letters"].append(letter.text.lower())
            elif letter_check == "correct":
                self.wordle["letters"][indx]["correct"] = letter.text.lower()
                self.wordle["present_letters"].append(letter.text.lower())
            elif letter_check == "present":
                self.wordle["present_letters"].append(letter.text.lower())
                self.wordle["letters"][indx]["incorrect"].append(letter.text.lower())

            self.wordle["guess"][row_number]["letters"].append(
                (letter.text, self.style_dict[letter_check])
            )

    def _check_for_present_letters(self, word):
        if self.wordle["present_letters"]:
            for present_letter in self.wordle["present_letters"]:
                if present_letter not in word:
                    return False
        return True

    def _get_potential_words(self):
        potential_words = {}
        for word in self.potential_words.keys():
            if self._check_for_present_letters(word) is False:
                continue

            for indx, letter in enumerate(word, start=1):
                if letter in self.wordle["absent_letters"]:
                    break
                if letter in self.wordle["letters"][indx]["incorrect"]:
                    break

                if not self.wordle["letters"][indx]["correct"]:
                    pass
                elif letter != self.wordle["letters"][indx]["correct"]:
                    break

                if indx == 5:
                    potential_words[word] = 1
        return potential_words

    def _check_for_win(self, check_word: str):
        for indx in range(1, 6):
            if not self.wordle["letters"][indx]["correct"]:
                return False
        if check_word != self.wordle_today:
            return False
        return True

    def _delete_guess(self, guess: str):
        for _ in range(5):
            self.action_chains.send_keys(Keys.BACK_SPACE).perform()
            time.sleep(0.1)
        try:
            self.potential_words.pop(guess)
        except KeyError:
            pass

        try:
            self.five_letter_words.pop(guess)
        except KeyError:
            pass

        with open(self.FIVE_LETTER_WORDS_ABSOLUTE_PATH, "w", encoding="utf-8") as file:
            file.write(json.dumps(self.five_letter_words, indent=1))

    def _get_available_letters(self) -> dict:
        availible_letters = {}
        for word in self.potential_words.keys():
            for letter in word:
                availible_letters[letter] = 1

        for indx in range(1, 6):
            try:
                availible_letters.pop(self.wordle["letters"][indx]["correct"])
            except KeyError:
                pass
        self.potential_letters = list(availible_letters.keys())
        return availible_letters

    def _get_best_guess(self, score: int = 5) -> str:
        """
        Generates a list of best guesses based on the remaining
        letters from the list of potential remaining words.

        Args:
            score (int, optional):
                Defaults to 5. Used in recusion. If function can't find a word that
                includes 5 unique letters from the list of potential letters
                then it will call the function again with a score of -= 1.

        Returns:
            guess (str):
                Random guess for the list of potential guesses.
        """
        best_guesses = []
        availible_letters = self._get_available_letters()

        if len(self.potential_words) == 1 or len(availible_letters) == 0:
            best_guess = list(self.potential_words.keys())[0]
            return best_guess

        if len(self.potential_words) == 2:
            best_guess = random.choice(list(self.potential_words.keys()))
            return best_guess

        for word in self.five_letter_words:
            for index, letter in enumerate(word, start=1):
                if self._is_letter_duplicate(letter=letter, word=word) is True:
                    break
                if letter in self.wordle["letters"][index]["incorrect"]:
                    break

                if index == 5:
                    word_score = 0
                    for availible_letter in availible_letters:
                        if availible_letter in word:
                            word_score += 1
                    if word_score == score:
                        best_guesses.append(word)
        if len(best_guesses) == 0:
            guess = self._get_best_guess(score=score - 1)
        else:
            guess = random.choice(best_guesses)
        return guess

    def _close_popups(self) -> None:
        """Closes the popups when done solving the Wordle."""
        WebDriverWait(self.browser, 5).until(
            EC.presence_of_element_located((By.CLASS_NAME, self.CLOSE_POPUP_CLASS))
        ).click()
        time.sleep(0.5)
        WebDriverWait(self.browser, 5).until(
            EC.presence_of_element_located((By.CLASS_NAME, self.CLOSE_POPUP_CLASS))
        ).click()

    def solve(self, first_guess: str = "") -> bool:
        """Solve the wordle by selecting random 'best guesses'.

        Args:
            first_guess (str, optional):
                The first guess the wordle solver will use.
                If blank, will just pick a random word. Defaults to "".

        Raises:
            ValueError:
                Will raise a ValueError if provided an invalid first guess.

        Returns:
            bool: True if successfully solved, False if otherwise.
        """
        with Live(self.build_layout()) as live:
            if first_guess:
                live.update(self.build_layout(guess=first_guess))
            if not first_guess:
                first_guess = random.choice(list(self.potential_words.keys()))
                live.update(self.build_layout(guess=first_guess))
                while self._submit_guess(guess=first_guess, row_number=1) is False:
                    live.update(self.build_layout(guess=first_guess, style="red bold"))
                    self._delete_guess(first_guess)
                    first_guess = random.choice(list(self.potential_words.keys()))
                    live.update(self.build_layout(guess=first_guess))
            elif self._submit_guess(guess=first_guess, row_number=1) is False:
                raise ValueError("You have provided an invalid first guess.")
            self._update_wordle(row_number=1, word=first_guess)
            live.update(self.build_layout())
            if self._check_for_win(first_guess) is True:
                self._close_popups()
                return True

            for indx in range(2, 7):
                self.potential_words = self._get_potential_words()
                new_guess = self._get_best_guess()
                live.update(self.build_layout(guess=new_guess))
                while self._submit_guess(guess=new_guess, row_number=indx) is False:
                    live.update(self.build_layout(guess=new_guess, style="red bold"))
                    self._delete_guess(new_guess)
                    new_guess = self._get_best_guess()
                    live.update(self.build_layout(guess=new_guess))
                self._update_wordle(row_number=indx, word=new_guess)
                live.update(self.build_layout())
                if self._check_for_win(new_guess) is True:
                    break

        self._close_popups()
        if self._check_for_win(new_guess) is True:
            self.console.print(
                f"Today's wordle is: [green bold]{self.wordle_today.upper()}",
                justify="center",
            )
            return True
        self.console.print(
            "Looks like the bot failed wordle today...", justify="center"
        )
        return False

wordle_today property

Grabs today's wordle from the Wordle Class's wordle dictionary. Only works if wordle has been solved.

Returns:

Name Type Description
str str

Today's wordle.

build_layout(guess='', style='yellow')

Dynamically build the layout in the console so the user can see how the wordle is being solved.

Parameters:

Name Type Description Default
guess str

The 5 letter word that is being guessed. Defaults to "".

''
style str

The color that the guess will be displayed as. Defaults to "yellow".

'yellow'

Returns:

Name Type Description
Layout Layout

Layout object for displaying wordle.

Source code in src/wordle_bot/wordle.py
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def build_layout(self, guess="", style="yellow") -> Layout:
    """
    Dynamically build the layout in the console so
    the user can see how the wordle is being solved.

    Args:
        guess (str, optional):
            The 5 letter word that is being guessed. Defaults to "".
        style (str, optional):
            The color that the guess will be displayed as. Defaults to "yellow".

    Returns:
        Layout: Layout object for displaying wordle.
    """

    print_guess = False
    table = Table(title="Wordle", show_header=False)
    table.add_column("Guess", width=5, justify="center")
    table.add_column("1", width=1, justify="center")
    table.add_column("2", width=1, justify="center")
    table.add_column("3", width=1, justify="center")
    table.add_column("4", width=1, justify="center")
    table.add_column("5", width=1, justify="center")
    for x in range(1, 7):
        if self.wordle["guess"][x]["letters"]:
            table.add_row(
                self.wordle["guess"][x]["word"].capitalize(),
                f"[{self.wordle['guess'][x]['letters'][0][1]}]{self.wordle['guess'][x]['letters'][0][0]}",
                f"[{self.wordle['guess'][x]['letters'][1][1]}]{self.wordle['guess'][x]['letters'][1][0]}",
                f"[{self.wordle['guess'][x]['letters'][2][1]}]{self.wordle['guess'][x]['letters'][2][0]}",
                f"[{self.wordle['guess'][x]['letters'][3][1]}]{self.wordle['guess'][x]['letters'][3][0]}",
                f"[{self.wordle['guess'][x]['letters'][4][1]}]{self.wordle['guess'][x]['letters'][4][0]}",
            )
            table.add_section()
        elif not guess:
            table.add_row(str(x), style="cyan")
            table.add_section()
        elif print_guess is False:
            print_guess = True
            table.add_row(guess.capitalize(), style=style)
            table.add_section()
        else:
            table.add_row(str(x), style="cyan")
            table.add_section()

    letters = Table(show_header=False, show_lines=False, show_edge=False)
    letters.add_row(
        f"Total potential words: [cyan bold]{len(self.potential_words.keys())}"
    )
    words = Table(show_header=False, show_lines=False, show_edge=False)
    words.add_row(str(self.potential_letters))
    words.add_section()
    words.add_row(str(list(self.potential_words.keys())))

    layout = Layout()
    layout.split_row(Layout(name="table"), Layout(name="info"))
    layout["info"].split_column(Layout(name="letters"), Layout(name="words"))
    layout["table"].size = 33
    layout["letters"].size = 3
    layout["table"].update(Panel(table))
    layout["letters"].update(Panel(letters))
    layout["words"].update(Panel(words))
    return layout

solve(first_guess='')

Solve the wordle by selecting random 'best guesses'.

Parameters:

Name Type Description Default
first_guess str

The first guess the wordle solver will use. If blank, will just pick a random word. Defaults to "".

''

Raises:

Type Description
ValueError

Will raise a ValueError if provided an invalid first guess.

Returns:

Name Type Description
bool bool

True if successfully solved, False if otherwise.

Source code in src/wordle_bot/wordle.py
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
def solve(self, first_guess: str = "") -> bool:
    """Solve the wordle by selecting random 'best guesses'.

    Args:
        first_guess (str, optional):
            The first guess the wordle solver will use.
            If blank, will just pick a random word. Defaults to "".

    Raises:
        ValueError:
            Will raise a ValueError if provided an invalid first guess.

    Returns:
        bool: True if successfully solved, False if otherwise.
    """
    with Live(self.build_layout()) as live:
        if first_guess:
            live.update(self.build_layout(guess=first_guess))
        if not first_guess:
            first_guess = random.choice(list(self.potential_words.keys()))
            live.update(self.build_layout(guess=first_guess))
            while self._submit_guess(guess=first_guess, row_number=1) is False:
                live.update(self.build_layout(guess=first_guess, style="red bold"))
                self._delete_guess(first_guess)
                first_guess = random.choice(list(self.potential_words.keys()))
                live.update(self.build_layout(guess=first_guess))
        elif self._submit_guess(guess=first_guess, row_number=1) is False:
            raise ValueError("You have provided an invalid first guess.")
        self._update_wordle(row_number=1, word=first_guess)
        live.update(self.build_layout())
        if self._check_for_win(first_guess) is True:
            self._close_popups()
            return True

        for indx in range(2, 7):
            self.potential_words = self._get_potential_words()
            new_guess = self._get_best_guess()
            live.update(self.build_layout(guess=new_guess))
            while self._submit_guess(guess=new_guess, row_number=indx) is False:
                live.update(self.build_layout(guess=new_guess, style="red bold"))
                self._delete_guess(new_guess)
                new_guess = self._get_best_guess()
                live.update(self.build_layout(guess=new_guess))
            self._update_wordle(row_number=indx, word=new_guess)
            live.update(self.build_layout())
            if self._check_for_win(new_guess) is True:
                break

    self._close_popups()
    if self._check_for_win(new_guess) is True:
        self.console.print(
            f"Today's wordle is: [green bold]{self.wordle_today.upper()}",
            justify="center",
        )
        return True
    self.console.print(
        "Looks like the bot failed wordle today...", justify="center"
    )
    return False