Created
August 22, 2019 20:36
-
-
Save djosephsen/1d526a850debb604600b045b6880d7fb to your computer and use it in GitHub Desktop.
A stupid little cli-thesaurus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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