diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-05-04 22:03:29 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-05-04 22:03:29 +0530 |
commit | fef62a0a13918c911b267e750a53453225fd68fe (patch) | |
tree | d3fd3286bbc8d74adab829c5e89fb9f5e005d22b | |
parent | 1d702df22b31d705a7255f9e84a7d8e516a94b18 (diff) | |
download | dict-master.tar.gz dict-master.tar.bz2 dict-master.zip |
-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 ''}'") |