random choice of first ten results, consistency with gis
This commit is contained in:
parent
db05fadc29
commit
0ee7ea1ac4
|
@ -1,3 +1,5 @@
|
||||||
|
import random
|
||||||
|
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,12 +10,12 @@ def giphy(inp, api_key=None):
|
||||||
'''.gif/.giphy <query> -- returns first giphy search result'''
|
'''.gif/.giphy <query> -- returns first giphy search result'''
|
||||||
url = 'http://api.giphy.com/v1/gifs/search'
|
url = 'http://api.giphy.com/v1/gifs/search'
|
||||||
try:
|
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:
|
except http.HTTPError as e:
|
||||||
return e.msg
|
return e.msg
|
||||||
|
|
||||||
results = response.get('data')
|
results = response.get('data')
|
||||||
if results:
|
if results:
|
||||||
return results[0].get('bitly_gif_url')
|
return random.choice(results).get('bitly_gif_url')
|
||||||
else:
|
else:
|
||||||
return 'no results found'
|
return 'no results found'
|
||||||
|
|
Loading…
Reference in New Issue