diff --git a/inventory-app/doorboy.py b/inventory-app/doorboy.py index 75f450a..6039d43 100644 --- a/inventory-app/doorboy.py +++ b/inventory-app/doorboy.py @@ -1,4 +1,5 @@ from datetime import datetime, timedelta +from dateutil.parser import parse from bson.objectid import ObjectId from flask import Blueprint, g, redirect, render_template, request @@ -223,6 +224,7 @@ class FormSwipe(FlaskForm): def view_swipe(): form = request.json print(form) + timestamp = parse(form["timestamp"]) if form.get("timestamp") else None now = datetime.utcnow() # Make sure token exists db.inventory.update_one({ @@ -231,7 +233,7 @@ def view_swipe(): "token.uid_hash": form["uid_hash"] }, { "$set": { - "last_seen": form.get("timestamp", now) + "last_seen": timestamp or now }, "$setOnInsert": { "component": "doorboy", @@ -252,7 +254,7 @@ def view_swipe(): event_swipe = { "component": "doorboy", - "timestamp": form["timestamp"], + "timestamp": timestamp, "door": form["door"], "event": "card-swiped", "success": form["success"], diff --git a/requirements.txt b/requirements.txt index 0b71610..2bd3f1b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,5 +13,6 @@ sepa Flask-WTF prometheus-flask-exporter pymongo +python-dateutil pyjwt[crypto] kubernetes