Generate dictionary source

This commit is contained in:
2024-11-02 22:51:27 +01:00
parent 4f3e0e4c19
commit 82d8926e0d
2 changed files with 10 additions and 1 deletions

View File

@@ -43,7 +43,6 @@ if settings.debug:
def get_game_id(): def get_game_id():
"""Calculate the index for the game/word we are handling today.""" """Calculate the index for the game/word we are handling today."""
print(settings.start_date)
today = date.today() today = date.today()
# Calculate the amount of days since the start of the games so we know which word is used today # Calculate the amount of days since the start of the games so we know which word is used today
return (today - settings.start_date).days return (today - settings.start_date).days
@@ -67,6 +66,7 @@ def handle_guess(word: Union[str, None] = None):
word_of_the_day = words[current_game_id].strip() word_of_the_day = words[current_game_id].strip()
if not is_valid_dictionary_word(word): if not is_valid_dictionary_word(word):
logger.info('Guess: %s for game %d (%s), word not found in dictionary', word, current_game_id, word_of_the_day)
return {'error': 'Word not in dictionary'} return {'error': 'Word not in dictionary'}
hint = 'it' hint = 'it'

View File

@@ -9,18 +9,27 @@ with open('basiswoorden-gekeurd.txt', 'r', encoding='utf-8') as wordfile:
all_words = wordfile.readlines() all_words = wordfile.readlines()
print(f'original list contains {len(all_words)} words') print(f'original list contains {len(all_words)} words')
dictionary_list = []
result_list = [] result_list = []
for word in all_words: for word in all_words:
word = word.strip() word = word.strip()
if word.isalpha() and word.lower() == word:
# Word is valid for our dictionary
dictionary_list.append(f'{word}\n')
if word.isalpha() and word.lower() == word and len(word) > MIN_LENGTH and len(word) <= MAX_LENGTH: if word.isalpha() and word.lower() == word and len(word) > MIN_LENGTH and len(word) <= MAX_LENGTH:
# Word is 'fit' for our game
result_list.append(f'{word}\n') result_list.append(f'{word}\n')
# print(result_list) # print(result_list)
print(f'words filtered: {len(result_list)} with length > {MIN_LENGTH} and <= {MAX_LENGTH}') print(f'words filtered: {len(result_list)} with length > {MIN_LENGTH} and <= {MAX_LENGTH}')
print(f'words in dictionary: {len(dictionary_list)}')
with open('filtered.txt', 'w', encoding='utf-8') as f: with open('filtered.txt', 'w', encoding='utf-8') as f:
f.writelines(result_list) f.writelines(result_list)
with open('dictionary.txt', 'w', encoding='utf-8') as f:
f.writelines(dictionary_list)
selection_list = [] selection_list = []
# Randomly select words for each day # Randomly select words for each day