From c2624687d85a87401c03f595cdd41027b03cfa99 Mon Sep 17 00:00:00 2001 From: Jordi Mas Date: Wed, 3 Apr 2024 09:30:46 +0200 Subject: [PATCH] Better handle of date param and standarize URL --- web_search.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/web_search.py b/web_search.py index 5193db6..59818cf 100755 --- a/web_search.py +++ b/web_search.py @@ -174,10 +174,14 @@ def memory_search_api(): return Response(search.get_json(), mimetype="application/json") -@app.route("/stats", methods=["GET"]) +@app.route("/stats/", methods=["GET"]) def stats_api(): - requested = request.args.get("date") - date_requested = datetime.datetime.strptime(requested, "%Y-%m-%d") + try: + requested = request.args.get('date') + date_requested = datetime.datetime.strptime(requested, '%Y-%m-%d') + except Exception as e: + return Response({}, mimetype="application/json", status=400) + stats = Stats() return Response(stats.get_json(date_requested), mimetype="application/json")