random choice of first ten results, consistency with gis

This commit is contained in:
bwreilly 2013-12-26 11:54:25 -08:00
parent db05fadc29
commit 0ee7ea1ac4
1 changed files with 4 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import random
from util import hook, http
@ -8,12 +10,12 @@ def giphy(inp, api_key=None):
'''.gif/.giphy <query> -- returns first giphy search result'''
url = 'http://api.giphy.com/v1/gifs/search'
try:
response = http.get_json(url, q=inp, limit=1, api_key=api_key)
response = http.get_json(url, q=inp, limit=10, api_key=api_key)
except http.HTTPError as e:
return e.msg
results = response.get('data')
if results:
return results[0].get('bitly_gif_url')
return random.choice(results).get('bitly_gif_url')
else:
return 'no results found'