1

sorting works

This commit is contained in:
ventilaar 2020-11-30 20:44:58 +01:00
parent 468b4598bb
commit e413ba8f8f
2 changed files with 33 additions and 11 deletions

27
poc.py
View File

@ -1,5 +1,5 @@
import json import json
from flask import Flask, render_template from flask import Flask, render_template, request
app = Flask(__name__) app = Flask(__name__)
@ -7,18 +7,23 @@ with open('steam.json') as file:
blob = json.load(file) blob = json.load(file)
def sortbyreleasedate():
return kek
def getfirstgamename():
return blob[0]
@app.route('/') @app.route('/')
def root(): def root():
return render_template('root.html', gfgn=getfirstgamename()) items = []
if request.args.get('sortby') == "name":
sortedblob = sorted(blob, key=lambda k: k['name'])
elif request.args.get('sortby') == "release_date":
sortedblob = sorted(blob, key=lambda k: k['release_date'])
elif request.args.get('sortby') == "price":
sortedblob = sorted(blob, key=lambda k: k['price'])
else:
sortedblob = blob
for x in range(0,99):
items.append(sortedblob[x])
return render_template('root.html', gfgn=blob[0], len=len(blob), items=items)

View File

@ -5,6 +5,23 @@
<body> <body>
<h1>Hello!</h1> <h1>Hello!</h1>
<p>Eerste game in de json blob is <b>{{ gfgn['name'] }}</b> met de game id <b>{{ gfgn['appid'] }}</b></p> <p>Eerste game in de json blob is <b>{{ gfgn['name'] }}</b> met de game id <b>{{ gfgn['appid'] }}</b></p>
<p>Totaal aantal games in json array is <b>{{ len }}</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 items %}
<tr style="text-align: center;">
<td>{{ row['appid'] }}</td>
<td>{{ row['name'] }}</td>
<td>{{ row['release_date'] }}</td>
<td>{{ row['price'] }} ,-</td>
</tr>
{% endfor %}
</table>
</body> </body>
</html> </html>