Get the dictionary definition of a word
README
The define
skill fetches the definition of words from Merriam Webster and displays them in chat. If you’re interested in synonyms of a word, consider using the synonyms
package.
This skill requires the following secrets to be configured:
apikey
DictionaryAPI api key
Code
import requests
subscription_key = bot.secrets.read(“apikey”)
if subscription_key is None:
bot.reply(“This skill needs an API key from https://dictionaryapi.com/. Register for a key there and add it as a secret called ‘apikey’ in the skill.”)
else:
search_term = bot.arguments
search_url = “https://dictionaryapi.com/api/v3/references/collegiate/json/” + search_term + “?key=” + subscription_key
response = requests.get(search_url)
response.raise_for_status()
search_results = response.json()
res = search_results[0]
if type(res) == str:
bot.reply(“Did you mean `” + res + “`?”)
else:
result = res.get(“shortdef”)
out = “* ” + “\n* “.join(result)
bot.reply(out)