|
6 | 6 | import string
|
7 | 7 | from typing import Set
|
8 | 8 | from selenium import webdriver
|
| 9 | +from selenium.webdriver.common.by import By |
9 | 10 | from selenium.webdriver.firefox.service import Service as FirefoxService
|
10 | 11 | from webdriver_manager.firefox import GeckoDriverManager
|
| 12 | +from pynput import keyboard |
| 13 | +import time |
| 14 | + |
| 15 | + |
| 16 | +# Check word length |
| 17 | +def check_word_length(word): |
| 18 | + if len(word) != 6: |
| 19 | + return False |
| 20 | + else: |
| 21 | + return True |
| 22 | + |
| 23 | + |
| 24 | +list_of_words = open("words_alpha.txt", "r").read().splitlines() |
| 25 | +list_of_words = list(filter(check_word_length, list_of_words)) |
| 26 | + |
| 27 | + |
| 28 | +def on_release(key): |
| 29 | + if key == keyboard.Key.esc: |
| 30 | + return False # stop listener |
| 31 | + |
| 32 | + |
| 33 | +def get_wordle_evaluation(game_row, browser): |
| 34 | + tiles = game_row.find_elements(By.CLASS_NAME, "Tile-module_tile__3ayIZ") |
| 35 | + evaluation = [] |
| 36 | + eval_to_int = { |
| 37 | + "correct": 1, |
| 38 | + "present": 0, |
| 39 | + "absent": -1, |
| 40 | + "empty": -2, |
| 41 | + "tbd": -3 |
| 42 | + } |
| 43 | + for tile in tiles: |
| 44 | + evaluation.append(eval_to_int[tile.get_attribute("data-state")]) |
| 45 | + print(evaluation) |
| 46 | + return tuple(evaluation) |
11 | 47 |
|
12 | 48 |
|
13 | 49 | def main():
|
14 | 50 | start_button = 'esc'
|
15 | 51 | browser = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
|
16 | 52 | browser.get("https://www.nytimes.com/games/wordle/index.html")
|
17 | 53 |
|
| 54 | + # Wait for start |
| 55 | + with keyboard.Listener(on_release=on_release) as listener: |
| 56 | + listener.join() |
| 57 | + print("Starting") |
| 58 | + |
| 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 | + |
| 66 | + 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) |
| 69 | + |
| 70 | + time.sleep(1) |
| 71 | + |
| 72 | + second_string = "tests" |
| 73 | + keyboard_controller.type(second_string) |
| 74 | + keyboard_controller.tap(keyboard.Key.enter) |
| 75 | + |
| 76 | + time.sleep(2) |
| 77 | + |
| 78 | + get_wordle_evaluation(game_rows[1], browser) |
| 79 | + |
| 80 | + |
18 | 81 | #From the basic list of words, return all the words with 5 characters.
|
19 | 82 | def get_list_of_five():
|
20 | 83 |
|
|
0 commit comments