From e413ba8f8f2dc90bdf1cbe8d390eaa6859fd8549 Mon Sep 17 00:00:00 2001 From: ventilaar Date: Mon, 30 Nov 2020 20:44:58 +0100 Subject: [PATCH] sorting works --- poc.py | 27 ++++++++++++++++----------- templates/root.html | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/poc.py b/poc.py index f4ca7ed..fed5f65 100644 --- a/poc.py +++ b/poc.py @@ -1,5 +1,5 @@ import json -from flask import Flask, render_template +from flask import Flask, render_template, request app = Flask(__name__) @@ -7,18 +7,23 @@ with open('steam.json') as file: blob = json.load(file) - -def sortbyreleasedate(): - return kek - - -def getfirstgamename(): - return blob[0] - - @app.route('/') 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) diff --git a/templates/root.html b/templates/root.html index 6e5b283..34ac96c 100644 --- a/templates/root.html +++ b/templates/root.html @@ -5,6 +5,23 @@

Hello!

Eerste game in de json blob is {{ gfgn['name'] }} met de game id {{ gfgn['appid'] }}

+

Totaal aantal games in json array is {{ len }}

+ + + + + + + + {% for row in items %} + + + + + + + {% endfor %} +
App IDNameRelease datePrice
{{ row['appid'] }}{{ row['name'] }}{{ row['release_date'] }}{{ row['price'] }} ,-
\ No newline at end of file