Last active
May 24, 2017 18:58
-
-
Save rgbkrk/8c8c6afa81de04e50721ba15ec60c1e0 to your computer and use it in GitHub Desktop.
Query giphy for random images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import IPython.display | |
import requests | |
def random_image_url(tags=None): | |
query = "" | |
if tags is not None: | |
query = "&tag=" + "+".join(tags) | |
api_url = "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC" + query | |
resp = requests.get(api_url) | |
data = resp.json()['data'] | |
if len(data) > 0: | |
return data['image_url'] | |
print("Sorry, we couldn't find an image for you. :(") | |
return "https://media3.giphy.com/media/3ornk0js8ki8oV5Wjm/giphy.gif" | |
def random_image(tags=None): | |
return IPython.display.Image(url=random_image_url(tags)) | |
jiff = random_image(["netflix"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment