add in giphy (.gif query)
This commit is contained in:
parent
bb3f418aa3
commit
db05fadc29
|
@ -0,0 +1,19 @@
|
||||||
|
from util import hook, http
|
||||||
|
|
||||||
|
|
||||||
|
@hook.api_key('giphy')
|
||||||
|
@hook.command('gif')
|
||||||
|
@hook.command
|
||||||
|
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)
|
||||||
|
except http.HTTPError as e:
|
||||||
|
return e.msg
|
||||||
|
|
||||||
|
results = response.get('data')
|
||||||
|
if results:
|
||||||
|
return results[0].get('bitly_gif_url')
|
||||||
|
else:
|
||||||
|
return 'no results found'
|
Loading…
Reference in New Issue