From 82bfe23747645301f0179f4de99feed0b9193884 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Mon, 16 Apr 2018 10:33:54 -0700 Subject: [PATCH] Fall back to pearson dictionary if urbandictionary doesnt know a word, fixes #27 --- app/define_word.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/define_word.py b/app/define_word.py index 067c5efc..65f194a1 100644 --- a/app/define_word.py +++ b/app/define_word.py @@ -15,7 +15,13 @@ def get_definition(content): ).json()['list'][0]['definition'] except IndexError: - definition = 'No definition found' + try: + # Try another dictionary + definition = requests.get( + "http://api.pearson.com/v2/dictionaries/ldoce5/entries?headword={}".format('%20'.join(word)) + ).json()['results'][0]['senses'][0]['definition'][0] + except IndexError: + definition = 'No definition found' return "`{}`\n```{}```".format(' '.join(word), definition)