From 6c004d14bd9f26c3972a8bda923bb75edbbe2242 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 7 Oct 2024 18:03:04 +1100 Subject: [PATCH] feat: Add now json endpoint --- server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.py b/server.py index 33a34e5..93a26a6 100644 --- a/server.py +++ b/server.py @@ -652,6 +652,18 @@ def now_rss(): rss += "" return make_response(rss, 200, {"Content-Type": "application/rss+xml"}) +@app.route("/now.json") +def now_json(): + now_pages = os.listdir("templates/now") + now_pages = [ + page for page in now_pages if page != "template.html" and page != "old.html" + ] + now_pages.sort(reverse=True) + host = "https://" + request.host + if ":" in request.host: + host = "http://" + request.host + now_pages = [{"url":host+"/now/"+page.strip(".html"), "date":datetime.datetime.strptime(page.strip(".html"), "%y_%m_%d").strftime("%A, %B %d, %Y"), "title":"What's Happening "+datetime.datetime.strptime(page.strip(".html"), "%y_%m_%d").strftime("%A, %B %d, %Y")} for page in now_pages] + return jsonify(now_pages) # endregion