README
Return the synonyms of a word, according to the Merriam Webster Thesaurus.
If you’re interested in getting the definition of a word, consider the define
skill.
This skill requires the following secrets to be configured:
apikey
API key from DictionaryAPI.com
Code
import requests
subscription_key = bot.secrets.read(«apikey»)
search_term = bot.arguments
search_url = «https://www.dictionaryapi.com/api/v3/references/thesaurus/json/» + search_term + «?key=» + subscription_key
response = requests.get(search_url)
response.raise_for_status()
search_results = response.json()
# Merriam Webster’s Thesaurus API returns two different data structures,
# depending on the the results.
# If it autocorrects the results, or can’t find an answer, it returns a vector of strings.
# If it finds an exact match, it will return a dictionary with the results.
if len(search_results) > 0:
if type(search_results[0]) == str:
bot.reply(«Did you mean `» + search_results[0] + «`?»)
elif type(search_results[0]) == dict:
meta = search_results[0].get(«meta»)
syns = meta.get(«syns»)
for syn in syns:
bot.reply(«* » + «, «.join(syn))
else:
bot.reply(«Couldn’t find any synonyms for `» + bot.arguments + «`.»)