forked from CMS/memberPlumbing
events: Get only needed records, write to file
This commit is contained in:
parent
aad4de1159
commit
07a7de5227
29
events.py
29
events.py
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from xml.etree import ElementTree as ET
|
from xml.etree import ElementTree as ET
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -64,15 +65,35 @@ parXMLIn = ET.Element("VertXMessage")
|
|||||||
ET.SubElement(parXMLIn, "hid:EventMessages", attrib={"action": "LR"})
|
ET.SubElement(parXMLIn, "hid:EventMessages", attrib={"action": "LR"})
|
||||||
parXMLOut = doXMLRequest(TARGET_IP, ET.tostring(parXMLIn))
|
parXMLOut = doXMLRequest(TARGET_IP, ET.tostring(parXMLIn))
|
||||||
|
|
||||||
|
root = None
|
||||||
|
if os.path.exists("log.xml"):
|
||||||
|
# read last log
|
||||||
|
tree = ET.ElementTree(None, "log.xml")
|
||||||
|
root = tree.getroot()
|
||||||
|
recordCount = int(parXMLOut[0].attrib["historyRecordMarker"]) - \
|
||||||
|
int(root[0][0].attrib["recordMarker"])
|
||||||
|
else:
|
||||||
|
# first run for this door
|
||||||
|
recordCount = 1000
|
||||||
|
|
||||||
|
print("Getting", recordCount, "records")
|
||||||
# get the actual messages
|
# get the actual messages
|
||||||
eventsXMLIn = ET.Element("VertXMessage")
|
eventsXMLIn = ET.Element("VertXMessage")
|
||||||
ET.SubElement(eventsXMLIn, "hid:EventMessages",
|
ET.SubElement(eventsXMLIn, "hid:EventMessages",
|
||||||
attrib={"action": "LR",
|
attrib={"action": "LR",
|
||||||
"recordCount": "1000",
|
"recordCount": str(recordCount),
|
||||||
"historyRecordMarker": parXMLOut[0].attrib["historyRecordMarker"],
|
"historyRecordMarker": parXMLOut[0].attrib["historyRecordMarker"],
|
||||||
"historyTimestamp": parXMLOut[0].attrib["historyTimestamp"]})
|
"historyTimestamp": parXMLOut[0].attrib["historyTimestamp"]})
|
||||||
eventsXMLOut = doXMLRequest(TARGET_IP, ET.tostring(eventsXMLIn))
|
eventsXMLOut = doXMLRequest(TARGET_IP, ET.tostring(eventsXMLIn))
|
||||||
|
#TODO: handle modeRecords=true
|
||||||
|
|
||||||
for event in eventsXMLOut[0]:
|
for index, event in enumerate(eventsXMLOut[0]):
|
||||||
ET.dump(event)
|
event.attrib["recordMarker"] = str(int(parXMLOut[0].attrib["historyRecordMarker"]) - index)
|
||||||
print(formatMessage(event))
|
# print(formatMessage(event))
|
||||||
|
|
||||||
|
if root is None:
|
||||||
|
tree = ET.ElementTree(eventsXMLOut)
|
||||||
|
else:
|
||||||
|
for event in reversed(eventsXMLOut[0]):
|
||||||
|
root[0].insert(0, event)
|
||||||
|
tree.write("log.xml")
|
||||||
|
Loading…
Reference in New Issue
Block a user