Skip to content

Commit

Permalink
Also store words in Drive, automatically download if not found locally.
Browse files Browse the repository at this point in the history
  • Loading branch information
fkodom committed Feb 3, 2022
1 parent ffacd91 commit 8d874c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down
14 changes: 14 additions & 0 deletions wordle/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]

0 comments on commit 8d874c1

Please sign in to comment.