From f6922739b9fd9ed46ccf6f3595c1686bcc66ef76 Mon Sep 17 00:00:00 2001 From: manetta Date: Mon, 21 Feb 2022 17:47:09 +0100 Subject: [PATCH] adding markdown support --- start.py | 60 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/start.py b/start.py index c5448f9..9026afb 100644 --- a/start.py +++ b/start.py @@ -32,33 +32,49 @@ def index(): @APP.route("/API/latest/") def latest(num): - request = feedtools.latest(num) - response = APP.response_class( - response=json.dumps(request), - status=200, - mimetype='application/json' - ) - return response + feed = feedtools.latest(num) + if flask.request.values.get("format") == 'md': + response_data = feedtools.md(feed) + mimetype_data = 'text/plain' + else: + response_data = json.dumps(feed) + mimetype_data = 'application/json' -@APP.route("/API/today/") + return APP.response_class( + response=response_data, + status=200, + mimetype=mimetype_data + ) + +@APP.route("/API/today") def today(): - request = feedtools.today() - response = APP.response_class( - response=json.dumps(request), - status=200, - mimetype='application/json' - ) - return response + feed = feedtools.today() + if flask.request.values.get("format") == 'md': + response_data = feedtools.md(feed) + mimetype_data = 'text/plain' + else: + response_data = json.dumps(feed) + mimetype_data = 'application/json' + return APP.response_class( + response=response_data, + status=200, + mimetype=mimetype_data + ) @APP.route("/API/past/") def past(days): - request = feedtools.past(days) - response = APP.response_class( - response=json.dumps(request), - status=200, - mimetype='application/json' - ) - return response + feed = feedtools.past(days) + if flask.request.values.get("format") == 'md': + response_data = feedtools.md(feed) + mimetype_data = 'text/plain' + else: + response_data = json.dumps(feed) + mimetype_data = 'application/json' + return APP.response_class( + response=response_data, + status=200, + mimetype=mimetype_data + ) if __name__ == "__main__": feedtools.update()