diff --git a/events.py b/events.py
index 1179b53..d64f9e2 100755
--- a/events.py
+++ b/events.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+from collections import defaultdict
from xml.etree import ElementTree as ET
import re
import requests
@@ -45,9 +46,17 @@ eventStrings = {
4045: 'Battery Failure',
}
-#
-
-#
+def formatMessage(event):
+ att = defaultdict(str, event.attrib)
+ eventType = int(att["eventType"])
+ return att["timestamp"], eventStrings[eventType].format(
+ 'ios-' + att['ioState'],
+ 'status-' + att['commandStatus'],
+ att['forename'] + " " + att['surname'],
+ att['rawCardNumber'],
+ att['oldTime'],
+ att['newTime'],
+ " IN" if att['readerAddress'] == '0' else " OUT")
# get parameters for messages to get?
# honestly not really sure why this is required, their API is confusing
@@ -66,13 +75,4 @@ eventsXMLOut = doXMLRequest(TARGET_IP, ET.tostring(eventsXMLIn))
for event in eventsXMLOut[0]:
ET.dump(event)
- att = event.attrib
- eventType = int(att["eventType"])
- print(att["timestamp"], eventStrings[eventType].format(
- 'ios-' + att.get('ioState', ''),
- 'status-' + att.get('commandStatus', ''),
- att.get('forename', '') + " " + att.get('surname', ''),
- att.get('rawCardNumber', ''),
- att.get('oldTime', ''),
- att.get('newTime', ''),
- "IN" if att.get("readerAddress", '') == '0' else "OUT"))
+ print(formatMessage(event))