Permalink
Browse files

Get GIPHY gif URL

  • Loading branch information...
minimaxir committed Sep 25, 2017
1 parent 3f626ae commit c2e4b6b9d58d1aa360f6f67a049ec962d0430b91
Showing with 22 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +19 −0 utils.py
View
@@ -0,0 +1,3 @@
secrets.py
cards.csv
*.cpython*
View
@@ -0,0 +1,19 @@
import requests
import time
from secrets import *
GIPHY_API_URL = "https://api.giphy.com/v1/gifs/random?api_key={}&tag={}"
def get_gif(name, GIPHY_API_KEY=GIPHY_API_KEY, max_attempts=10):
attempts = 0
while attempts < max_attempts:
r = requests.get(GIPHY_API_URL.format(GIPHY_API_KEY, name))
gif = r.json()['data']
ratio = int(gif['image_width']) / int(gif['image_height'])
# return gif['image_mp4_url']
# print(ratio)
if 1.2 < ratio < 1.6:
return gif['image_mp4_url']
attempts += 1
time.sleep(1)

0 comments on commit c2e4b6b

Please sign in to comment.