From 8d874c111fa0cd3a86c191a32310c78f62e1c987 Mon Sep 17 00:00:00 2001 From: Frank Odom Date: Thu, 3 Feb 2022 15:55:09 -0600 Subject: [PATCH] Also store words in Drive, automatically download if not found locally. --- setup.py | 2 +- wordle/data.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index de836c3..9d764c4 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ def get_version_tag() -> str: description="A minimal Python library for playing and solving 'Wordle' problems", long_description=open("README.md").read(), long_description_content_type="text/markdown", - install_requires=["colorama", "regex"], + install_requires=["colorama", "gdown", "regex"], extras_require=extras_require, data_files=[("data", ["data/words.txt"])], entry_points={ diff --git a/wordle/data.py b/wordle/data.py index 674c36f..c5238e8 100644 --- a/wordle/data.py +++ b/wordle/data.py @@ -2,12 +2,26 @@ from functools import lru_cache from typing import List +import gdown + +WORDS_URL = ( + "https://drive.google.com/uc?id=1upgBKczLa9CU1q1V-_Hsi3ImPfPGqevb" + # https://drive.google.com/file/d/1upgBKczLa9CU1q1V-_Hsi3ImPfPGqevb/view?usp=sharing +) WORDS_PATH = os.path.join( os.path.dirname(__file__), os.path.pardir, "data", "words.txt" ) +def _download_words(): + os.makedirs(os.path.dirname(WORDS_PATH), exist_ok=True) + gdown.download(WORDS_URL, WORDS_PATH) + + @lru_cache() def load_words() -> List[str]: + if not os.path.exists(WORDS_PATH): + _download_words() + with open(WORDS_PATH, "r") as f: return [line.lower().strip() for line in f.readlines()]