From 462e7ba08af407b535a357e974cf76240d9c4325 Mon Sep 17 00:00:00 2001 From: Robin Richtsfeld Date: Tue, 31 Jul 2018 04:53:37 +0200 Subject: [PATCH] Fix urbandict data['result_type'] --- modules/urbandict.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/modules/urbandict.py b/modules/urbandict.py index 89d3fe6..52485f1 100644 --- a/modules/urbandict.py +++ b/modules/urbandict.py @@ -17,13 +17,6 @@ def urbandict(phenny, input): phenny.say(urbandict.__doc__.strip()) return - # create opener - #opener = urllib.request.build_opener() - #opener.addheaders = [ - # ('User-agent', web.Grab().version), - # ('Referer', "http://m.urbandictionary.com"), - #] - try: data = web.get( "http://api.urbandictionary.com/v0/define?term={0}".format( @@ -33,11 +26,13 @@ def urbandict(phenny, input): raise GrumbleError( "Urban Dictionary slemped out on me. Try again in a minute.") - if data['result_type'] == 'no_results': + results = data['list'] + + if not results: phenny.say("No results found for {0}".format(word)) return - result = data['list'][0] + result = results[0] url = 'http://www.urbandictionary.com/define.php?term={0}'.format( web.quote(word))