events: Move into main() method
This commit is contained in:
parent
07a7de5227
commit
d62f0c16ab
72
events.py
72
events.py
@ -59,41 +59,45 @@ def formatMessage(event):
|
|||||||
att['newTime'],
|
att['newTime'],
|
||||||
" IN" if att['readerAddress'] == '0' else " OUT")
|
" IN" if att['readerAddress'] == '0' else " OUT")
|
||||||
|
|
||||||
# get parameters for messages to get?
|
def main():
|
||||||
# honestly not really sure why this is required, their API is confusing
|
# get parameters for messages to get?
|
||||||
parXMLIn = ET.Element("VertXMessage")
|
# honestly not really sure why this is required, their API is confusing
|
||||||
ET.SubElement(parXMLIn, "hid:EventMessages", attrib={"action": "LR"})
|
parXMLIn = ET.Element("VertXMessage")
|
||||||
parXMLOut = doXMLRequest(TARGET_IP, ET.tostring(parXMLIn))
|
ET.SubElement(parXMLIn, "hid:EventMessages", attrib={"action": "LR"})
|
||||||
|
parXMLOut = doXMLRequest(TARGET_IP, ET.tostring(parXMLIn))
|
||||||
|
|
||||||
root = None
|
root = None
|
||||||
if os.path.exists("log.xml"):
|
if os.path.exists("log.xml"):
|
||||||
# read last log
|
# read last log
|
||||||
tree = ET.ElementTree(None, "log.xml")
|
tree = ET.ElementTree(None, "log.xml")
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
recordCount = int(parXMLOut[0].attrib["historyRecordMarker"]) - \
|
recordCount = int(parXMLOut[0].attrib["historyRecordMarker"]) - \
|
||||||
int(root[0][0].attrib["recordMarker"])
|
int(root[0][0].attrib["recordMarker"])
|
||||||
else:
|
else:
|
||||||
# first run for this door
|
# first run for this door
|
||||||
recordCount = 1000
|
recordCount = 1000
|
||||||
|
|
||||||
print("Getting", recordCount, "records")
|
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": str(recordCount),
|
"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
|
#TODO: handle modeRecords=true
|
||||||
|
|
||||||
for index, event in enumerate(eventsXMLOut[0]):
|
for index, event in enumerate(eventsXMLOut[0]):
|
||||||
event.attrib["recordMarker"] = str(int(parXMLOut[0].attrib["historyRecordMarker"]) - index)
|
event.attrib["recordMarker"] = str(int(parXMLOut[0].attrib["historyRecordMarker"]) - index)
|
||||||
# print(formatMessage(event))
|
# print(formatMessage(event))
|
||||||
|
|
||||||
if root is None:
|
if root is None:
|
||||||
tree = ET.ElementTree(eventsXMLOut)
|
tree = ET.ElementTree(eventsXMLOut)
|
||||||
else:
|
else:
|
||||||
for event in reversed(eventsXMLOut[0]):
|
for event in reversed(eventsXMLOut[0]):
|
||||||
root[0].insert(0, event)
|
root[0].insert(0, event)
|
||||||
tree.write("log.xml")
|
tree.write("log.xml")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
Reference in New Issue
Block a user