Skip to content

Instantly share code, notes, and snippets.

@djosephsen
Created August 22, 2019 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djosephsen/1d526a850debb604600b045b6880d7fb to your computer and use it in GitHub Desktop.
Save djosephsen/1d526a850debb604600b045b6880d7fb to your computer and use it in GitHub Desktop.
A stupid little cli-thesaurus
#!/usr/bin/env python
import sys
import requests
from termcolor import colored
# get an api key from https://dictionaryapi.com/register/index
APIKEY = '<your api key here>'
URL = 'https://www.dictionaryapi.com/api/v3/references/thesaurus/json/'
word = sys.argv[1]
query = "{}{}?key={}".format(URL,word,APIKEY)
resp = requests.get(query)
print("(API Response:{})".format(resp.status_code))
data = resp.json()
#print in reverse order so the most relevant results print closest to the cursor
for k in range((len(data)-1), -1, -1):
sense = data[k]
print(colored("{} :: {}\n{}".format(sense['meta']['id'],sense['fl'], sense['shortdef'][0]),'yellow'))
#print(colored(sense['meta']['syns']),'blue')
for syn in sense['meta']['syns']:
print(colored("{} ".format(syn),'white'))
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment