-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (41 loc) · 2.58 KB
/
main.py
File metadata and controls
53 lines (41 loc) · 2.58 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, request, render_template
import http.client
import json
app = Flask(__name__)
searchDict = {}
@app.route("/", methods=['GET', 'POST'] )
def root():
return render_template("index.html")
@app.route("/search")
def search():
return render_template("second.html", jsonObj = "", start = 1)
#return render_template("tempsecond.html", jsonObj = "", start = 1)
@app.route("/search", methods=['POST'])
def search_post():
str = request.form['text']
select = request.form['selection']
if str != "":
result = finderCall(str, select)
result = [item for item in result["results"] if item['ratingsSummary']['voteCount'] > 100000]
if result:
return render_template("second.html", jsonObj = result, start = 0)
#return render_template("tempsecond.html", jsonObj = result, start = 0)
else:
return render_template("second.html", jsonObj = "", start = 0)
#return render_template("tempsecond.html", jsonObj = "", start = 0)
else:
return render_template("second.html", jsonObj = "", start = 0)
#return render_template("tempsecond.html", jsonObj = "", start = 0)
def finderCall(str, select):
conn = http.client.HTTPSConnection("moviesdatabase.p.rapidapi.com")
headers = {
##API used:
'X-RapidAPI-Key': "8bf0871ea3msh8bbb7d0dd036a04p15f9cajsn0e547477cf42",
'X-RapidAPI-Host': "moviesdatabase.p.rapidapi.com"
}
conn.request("GET", "/titles/search/title/" + str.replace(" ", "%20") + "?exact=false&info=base_info&titleType=" + select + "&limit=50", headers=headers)
res = conn.getresponse()
data = res.read()
return json.loads(data.decode("utf-8"))
if __name__ == "__main__":
app.run()