diff --git a/helpers/events.py b/helpers/events.py index 12303fb..d5915fd 100644 --- a/helpers/events.py +++ b/helpers/events.py @@ -49,5 +49,13 @@ class Events: cw.writerow(row) return si.getvalue() + def today_json(self): + values = self.collection.find({"date": self.today}) + values = {value['event']: value['count'] for value in values} + json_data = {} + for metric in self.metrics: + json_data[metric] = values.get(metric) or 0 + return json_data + events = Events() diff --git a/main.py b/main.py index 977770f..657ffdf 100644 --- a/main.py +++ b/main.py @@ -28,4 +28,8 @@ def run(): output.headers["Content-type"] = "text/csv" return output + @app.route('/stats/today', methods=["GET"]) + def today(): + return events.today_json() + app.run(host="0.0.0.0", port=8000)