Commit edf98107 authored by Otthorn's avatar Otthorn 🤔

Delete giphy_api.py

parent fc5a8b23
import random
import json
from urllib.request import urlopen
from urllib.parse import quote_plus
from parse_env import parse_env
# parse the api_key from the env
dico_env = parse_env("giphy.env")
api_key = dico_env['api_key']
limit = "25"
def gif_search(query, limit=limit, api_key=api_key):
query = quote_plus(query) # make the query browser compliant
data = json.loads(urlopen("http://api.giphy.com/v1/gifs/search?q="+query+"&api_key="+api_key+"&limit="+limit).read())
random_id = random.randint(0, int(limit) -1 )
#print("GIPHY API: ", random_id)
id = data['data'][random_id]['id']
#print("GIPHY API: ", id)
url_gif = "https://i.giphy.com/media/"+id+"/giphy.gif"
mime = "image/gif" # mime type of the image
data_bytes = urlopen(url_gif).read()
return data_bytes, mime
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment