-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (40 loc) · 1.67 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, render_template, request, redirect, url_for
import pandas as pd
from ast import literal_eval
pd.options.mode.chained_assignment = None
metadata = pd.read_csv('datasets/data_to_show_app.csv',
converters={'index': literal_eval, 'result': literal_eval, 'url_links': literal_eval,
'score': literal_eval})
urls = pd.read_csv('datasets/urls.csv', converters={'urls': literal_eval}, index_col=0)
s = pd.Series(metadata.name_game)
app = Flask(__name__)
# Method returns list of links to images
def getUrls(indexes, urls):
data = []
for idx in indexes[0]:
if len(urls.to_numpy()[idx, 0]) > 0:
data.append(urls.to_numpy()[idx, 0][0])
return data
# Main page
@app.route('/')
def home():
return render_template('index.html')
@app.route('/error')
def bad_value():
return render_template('error.html')
# Page with results
@app.route('/content', methods=['GET', 'POST'])
def get_data():
if request.method == 'POST' or request.method == 'GET':
user = request.form['search']
if user in s.values:
index = metadata[metadata.name_game == user].iloc[:, 0].to_list()
links = getUrls(index, urls)
game = metadata[metadata.name_game == user].iloc[:, 2].to_list()[0]
link = metadata[metadata.name_game == user].iloc[:, 3].to_list()[0]
score = metadata[metadata.name_game == user].iloc[:, 4].to_list()[0]
return render_template('content.html', game=game, link=link, score=score, user=user, links=links)
else:
return render_template('error.html')
if __name__ == "__main__":
app.run()