mirror of
https://github.com/aquatix/alfagok.git
synced 2025-12-06 23:25:09 +01:00
Generate dictionary source
This commit is contained in:
@@ -43,7 +43,6 @@ if settings.debug:
|
||||
|
||||
def get_game_id():
|
||||
"""Calculate the index for the game/word we are handling today."""
|
||||
print(settings.start_date)
|
||||
today = date.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
|
||||
@@ -67,6 +66,7 @@ def handle_guess(word: Union[str, None] = None):
|
||||
word_of_the_day = words[current_game_id].strip()
|
||||
|
||||
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'}
|
||||
|
||||
hint = 'it'
|
||||
|
||||
@@ -9,18 +9,27 @@ with open('basiswoorden-gekeurd.txt', 'r', encoding='utf-8') as wordfile:
|
||||
all_words = wordfile.readlines()
|
||||
print(f'original list contains {len(all_words)} words')
|
||||
|
||||
dictionary_list = []
|
||||
result_list = []
|
||||
for word in all_words:
|
||||
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:
|
||||
# Word is 'fit' for our game
|
||||
result_list.append(f'{word}\n')
|
||||
|
||||
# print(result_list)
|
||||
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:
|
||||
f.writelines(result_list)
|
||||
|
||||
with open('dictionary.txt', 'w', encoding='utf-8') as f:
|
||||
f.writelines(dictionary_list)
|
||||
|
||||
selection_list = []
|
||||
|
||||
# Randomly select words for each day
|
||||
|
||||
Reference in New Issue
Block a user