niet meer aan poc.py werken, run.py aangemaakt om sorting.py te importeren en uit te testen
This commit is contained in:
parent
3af9ca16b1
commit
170811d879
2
poc.py
2
poc.py
@ -23,7 +23,7 @@ def root():
|
||||
for x in range(0,99):
|
||||
items.append(sortedblob[x])
|
||||
|
||||
return render_template('root.html', gfgn=blob[0], len=len(blob), items=items)
|
||||
return render_template('poc.html', gfgn=blob[0], len=len(blob), items=items)
|
||||
|
||||
|
||||
|
||||
|
53
run.py
Normal file
53
run.py
Normal file
@ -0,0 +1,53 @@
|
||||
import json
|
||||
from flask import Flask, render_template, request
|
||||
import sorting
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# lees json bestand en maak de tabel structuur aan, data_tpl
|
||||
with open('steam.json') as file:
|
||||
# laad de json in een list
|
||||
blob = json.load(file)
|
||||
|
||||
# lege lijst aanmaken
|
||||
temp_biglst = []
|
||||
|
||||
# voor elke item in de list
|
||||
for i in blob:
|
||||
# voeg elke regel in de item toe aan een tijdelijke list
|
||||
temp_lst = [i['appid'], i['name'], i['release_date'], i['english'], i['developer'], i['publisher'],
|
||||
i['platforms'], i['required_age'], i['categories'], i['genres'], i['steamspy_tags'],
|
||||
i['achievements'], i['positive_ratings'], i['negative_ratings'], i['average_playtime'],
|
||||
i['median_playtime'], i['owners'], i['price']]
|
||||
|
||||
# zet de tijdelijke lijst om in een tuple
|
||||
temp_tpl = tuple(temp_lst)
|
||||
# voeg de tijdelijke list toe in de datalijst
|
||||
temp_biglst.append(temp_tpl)
|
||||
|
||||
# datalijst omzetten in tuple, dit is de globale variabele die opgeroepen mag worden
|
||||
data_tpl = tuple(temp_biglst)
|
||||
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def root():
|
||||
entries = []
|
||||
|
||||
if request.args.get('sortby') == "name":
|
||||
data_lst = sorting.qsort(data_tpl, 1)
|
||||
elif request.args.get('sortby') == "release_date":
|
||||
data_lst = sorting.qsort(data_tpl, 2)
|
||||
elif request.args.get('sortby') == "price":
|
||||
data_lst = sorting.qsort(data_tpl, 17)
|
||||
else:
|
||||
data_lst = data_tpl # hoezo memory efficient werken?
|
||||
|
||||
for x in range(0,99):
|
||||
entries.append(data_lst[x])
|
||||
|
||||
return render_template('index.html', first_entry=data_tpl[0], sizedb=len(data_tpl), entries=entries)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run('0.0.0.0', port=5001, debug=True)
|
32
sorting.py
32
sorting.py
@ -1,30 +1,3 @@
|
||||
import json
|
||||
|
||||
# lees json bestand en maak de tabel structuur aan, data_tpl
|
||||
with open('steam.json') as file:
|
||||
# laad de json in een list
|
||||
blob = json.load(file)
|
||||
|
||||
# lege lijst aanmaken
|
||||
temp_biglst = []
|
||||
|
||||
# voor elke item in de list
|
||||
for i in blob:
|
||||
# voeg elke regel in de item toe aan een tijdelijke list
|
||||
temp_lst = [i['appid'], i['name'], i['release_date'], i['english'], i['developer'], i['publisher'],
|
||||
i['platforms'], i['required_age'], i['categories'], i['genres'], i['steamspy_tags'],
|
||||
i['achievements'], i['positive_ratings'], i['negative_ratings'], i['average_playtime'],
|
||||
i['median_playtime'], i['owners'], i['price']]
|
||||
|
||||
# zet de tijdelijke lijst om in een tuple
|
||||
temp_tpl = tuple(temp_lst)
|
||||
# voeg de tijdelijke list toe in de datalijst
|
||||
temp_biglst.append(temp_tpl)
|
||||
|
||||
# datalijst omzetten in tuple, dit is de globale variabele die opgeroepen mag worden
|
||||
data_tpl = tuple(temp_biglst)
|
||||
|
||||
|
||||
def qsort(tpl, colnum, reverse=False):
|
||||
|
||||
small = []
|
||||
@ -52,8 +25,3 @@ def qsort(tpl, colnum, reverse=False):
|
||||
return qsort(small, colnum, reverse) + same + qsort(large, colnum, reverse)
|
||||
else:
|
||||
return tpl
|
||||
|
||||
|
||||
qsort(data_tpl, 0, True)
|
||||
|
||||
|
||||
|
27
templates/index.html
Normal file
27
templates/index.html
Normal file
@ -0,0 +1,27 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Index</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello!</h1>
|
||||
<p>Eerste game in memory is <b>{{ first_entry[1] }}</b> met de game id <b>{{ first_entry[0] }}</b></p>
|
||||
<p>Totaal aantal games in json array is <b>{{ sizedb }}</b></p>
|
||||
<table style="width:50%">
|
||||
<tr>
|
||||
<th><a href="/">App ID</a></th>
|
||||
<th><a href="?sortby=name">Name</a></th>
|
||||
<th><a href="?sortby=release_date">Release date</a></th>
|
||||
<th><a href="?sortby=price">Price</a></th>
|
||||
</tr>
|
||||
{% for row in entries %}
|
||||
<tr style="text-align: center;">
|
||||
<td>{{ row[0] }}</td>
|
||||
<td>{{ row[1] }}</td>
|
||||
<td>{{ row[2] }}</td>
|
||||
<td>{{ row[17] }} ,-</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user