2021-08-13 20:49:34 +00:00
|
|
|
from flask import *
|
|
|
|
from os import environ
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from files.__main__ import app
|
|
|
|
|
|
|
|
GIPHY_KEY = environ.get('GIPHY_KEY').rstrip()
|
|
|
|
|
|
|
|
|
2021-10-03 19:05:59 +00:00
|
|
|
@app.get("/giphy")
|
|
|
|
@app.get("/giphy<path>")
|
2021-09-16 21:06:30 +00:00
|
|
|
def giphy(path=None):
|
2021-08-13 20:49:34 +00:00
|
|
|
|
2021-10-12 05:23:17 +00:00
|
|
|
searchTerm = request.values.get("searchTerm", "").strip()
|
2021-09-19 13:11:34 +00:00
|
|
|
limit = int(request.values.get("limit", 48))
|
2021-09-08 08:53:57 +00:00
|
|
|
if searchTerm and limit:
|
|
|
|
url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit={limit}"
|
|
|
|
elif searchTerm and not limit:
|
|
|
|
url = f"https://api.giphy.com/v1/gifs/search?q={searchTerm}&api_key={GIPHY_KEY}&limit=48"
|
|
|
|
else:
|
|
|
|
url = f"https://api.giphy.com/v1/gifs?api_key={GIPHY_KEY}&limit=48"
|
2021-09-16 21:06:30 +00:00
|
|
|
return jsonify(requests.get(url).json())
|