Skip to content

Instantly share code, notes, and snippets.

@rgbkrk
Last active May 24, 2017 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgbkrk/8c8c6afa81de04e50721ba15ec60c1e0 to your computer and use it in GitHub Desktop.
Save rgbkrk/8c8c6afa81de04e50721ba15ec60c1e0 to your computer and use it in GitHub Desktop.
Query giphy for random images
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