From c3daf52f033fc1a35317e8a4d6840b1d2a410030 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Thu, 9 Jul 2020 17:49:13 +0200 Subject: [PATCH] default to latest in /news --- server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 074ccc2..331d80d 100755 --- a/server.py +++ b/server.py @@ -137,17 +137,19 @@ def people(): @app.route("/news") def news(): - uid = int(flask.request.args.get("uid")) + uid = flask.request.args.get("uid") news = parseNewsDirWithTimeout() newsDict = dict() for n in news: newsDict.update( { n["uid"] : n } ) - if not uid or not newsDict[uid]: + if not uid: + article = sorted(news, key=lambda n: n["parsed-time"])[-1] + elif not newsDict[int(uid)]: return ("", 404) - - article = newsDict[uid] + else: + article = newsDict[int(uid)] try: with open(article["markdown-file"]) as f: article.update( { "markdown-content" : markdown2.markdown(f.read()) } )