Parse swipe timestamp format
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful

This commit is contained in:
Madis Mägi 2023-08-11 22:05:05 +03:00
parent 59d756a845
commit 43776722a1
2 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,5 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dateutil.parser import parse
from bson.objectid import ObjectId from bson.objectid import ObjectId
from flask import Blueprint, g, redirect, render_template, request from flask import Blueprint, g, redirect, render_template, request
@ -223,6 +224,7 @@ class FormSwipe(FlaskForm):
def view_swipe(): def view_swipe():
form = request.json form = request.json
print(form) print(form)
timestamp = parse(form["timestamp"]) if form.get("timestamp") else None
now = datetime.utcnow() now = datetime.utcnow()
# Make sure token exists # Make sure token exists
db.inventory.update_one({ db.inventory.update_one({
@ -231,7 +233,7 @@ def view_swipe():
"token.uid_hash": form["uid_hash"] "token.uid_hash": form["uid_hash"]
}, { }, {
"$set": { "$set": {
"last_seen": form.get("timestamp", now) "last_seen": timestamp or now
}, },
"$setOnInsert": { "$setOnInsert": {
"component": "doorboy", "component": "doorboy",
@ -252,7 +254,7 @@ def view_swipe():
event_swipe = { event_swipe = {
"component": "doorboy", "component": "doorboy",
"timestamp": form["timestamp"], "timestamp": timestamp,
"door": form["door"], "door": form["door"],
"event": "card-swiped", "event": "card-swiped",
"success": form["success"], "success": form["success"],

View File

@ -13,5 +13,6 @@ sepa
Flask-WTF Flask-WTF
prometheus-flask-exporter prometheus-flask-exporter
pymongo pymongo
python-dateutil
pyjwt[crypto] pyjwt[crypto]
kubernetes kubernetes