2021-10-15 14:08:27 +00:00
|
|
|
from flask import *
|
|
|
|
from os import environ
|
|
|
|
import requests
|
2022-01-11 21:53:49 +00:00
|
|
|
from files.helpers.wrappers import *
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
from files.__main__ import app
|
|
|
|
|
|
|
|
GIPHY_KEY = environ.get('GIPHY_KEY').rstrip()
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/giphy")
|
|
|
|
@app.get("/giphy<path>")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2022-01-11 21:53:49 +00:00
|
|
|
def giphy(v=None, path=None):
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
searchTerm = request.values.get("searchTerm", "").strip()
|
|
|
|
limit = int(request.values.get("limit", 48))
|
|
|
|
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-11-14 01:19:32 +00:00
|
|
|
return jsonify(requests.get(url, timeout=5).json())
|