-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
31 lines (24 loc) · 901 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
from decouple import config
from flask import Flask, render_template, request
app = Flask(__name__)
apiurl = "https://tenor.googleapis.com/v2/search"
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
search_query = request.form['search_query']
# Parameters for the Tenor API request
params = {
'key': config("API_KEY"),
'q': search_query,
'client_key': "in_a_jiff",
'limit': 9
}
response = requests.get(apiurl, params=params)
json_data = response.json()
gif_urls = [result["media_formats"]["gif"]["url"] for result in json_data['results']]
return render_template('results.html', gif_urls=gif_urls, search_query=search_query)
else:
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)