Browse Source

add checkin time

Davide Alberani 7 years ago
parent
commit
7aee068c66
2 changed files with 28 additions and 0 deletions
  1. 7 0
      tools/qrcode_reader.ini
  2. 21 0
      tools/qrcode_reader.py

+ 7 - 0
tools/qrcode_reader.ini

@@ -10,11 +10,18 @@ username = admin
 password = eventman
 ca = 
 
+# in the 'event' section you have to specify the ID of the event,
+# the name of the field used to search for tickets and - optionally -
+# the number of chars in the field value that will be considered
+# for the match (limit_field)
 [event]
 id = 1492099112_2612922-3896-9zwsccuvguz91jtw9y6lwvkud11ba7wt
 field = order_nr
 limit_field = 9
 
+# the 'actions' section key: value pairs are used in the PUT method.
 [actions]
 attended = True
 checked_in_by = ${eventman:username}
+checkin_datetime = %NOW%
+

+ 21 - 0
tools/qrcode_reader.py

@@ -22,10 +22,12 @@ import os
 import io
 import sys
 import time
+import json
 import serial
 import urllib
 import logging
 import argparse
+import datetime
 import requests
 import configparser
 from requests.packages.urllib3.exceptions import InsecureRequestWarning
@@ -49,6 +51,8 @@ def convert_obj(obj):
             return True
         elif obj_l in ['false', 'off', 'no']:
             return False
+        elif obj == '%NOW%':
+            return datetime.datetime.utcnow()
     return obj
 
 
@@ -63,6 +67,23 @@ def convert(seq):
     return convert_obj(seq)
 
 
+class ImprovedEncoder(json.JSONEncoder):
+    """Enhance the default JSON encoder to serialize datetime instances."""
+    def default(self, o):
+        if isinstance(o, (datetime.datetime, datetime.date,
+                datetime.time, datetime.timedelta)):
+            try:
+                return str(o)
+            except Exception as e:
+                pass
+        elif isinstance(o, set):
+            return list(o)
+        return json.JSONEncoder.default(self, o)
+
+# Inject our class as the default encoder.
+json._default_encoder = ImprovedEncoder()
+
+
 class Connector():
     def __init__(self, cfg):
         self.cfg = cfg