diff options
-rwxr-xr-x | dict.py | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -8,7 +8,7 @@ import sys # Import for potential error handling # Customizable word list path WORD_LIST_PATH = "~/.local/share/vocab/words.txt" -def get_random_word_from_urban_dictionary(): +def fetch_dict(): """Retrieves a random word and definition from Urban Dictionary API.""" url = "http://api.urbandictionary.com/v0/random" @@ -24,7 +24,7 @@ def get_random_word_from_urban_dictionary(): except requests.exceptions.RequestException: return None, None -def get_random_word_from_local_file(): +def local_dict(): """Retrieves a random word from the local word list.""" try: # Expand '~' for the home directory in the path @@ -40,10 +40,10 @@ def get_random_word_from_local_file(): return None if __name__ == "__main__": - word, definition = get_random_word_from_urban_dictionary() + word, definition = fetch_dict() if not word: # Check if word retrieval failed - word = get_random_word_from_local_file() + word = local_dict() if word: os.system(f"cowsay '{word} -> {definition if definition else ''}'") |