Fix urbandict data['result_type']

master
Robin Richtsfeld 2018-07-31 04:53:37 +02:00
parent 44084c8739
commit 462e7ba08a
1 changed files with 4 additions and 9 deletions

View File

@ -17,13 +17,6 @@ def urbandict(phenny, input):
phenny.say(urbandict.__doc__.strip()) phenny.say(urbandict.__doc__.strip())
return return
# create opener
#opener = urllib.request.build_opener()
#opener.addheaders = [
# ('User-agent', web.Grab().version),
# ('Referer', "http://m.urbandictionary.com"),
#]
try: try:
data = web.get( data = web.get(
"http://api.urbandictionary.com/v0/define?term={0}".format( "http://api.urbandictionary.com/v0/define?term={0}".format(
@ -33,11 +26,13 @@ def urbandict(phenny, input):
raise GrumbleError( raise GrumbleError(
"Urban Dictionary slemped out on me. Try again in a minute.") "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)) phenny.say("No results found for {0}".format(word))
return return
result = data['list'][0] result = results[0]
url = 'http://www.urbandictionary.com/define.php?term={0}'.format( url = 'http://www.urbandictionary.com/define.php?term={0}'.format(
web.quote(word)) web.quote(word))