2018-05-09 21:26:20 -04:00
|
|
|
#!/usr/bin/env python3
|
2018-05-14 22:53:26 -04:00
|
|
|
from collections import defaultdict
|
2018-08-16 12:52:25 -04:00
|
|
|
from lxml import etree
|
2018-05-27 17:44:00 -04:00
|
|
|
import os
|
2018-05-14 22:37:17 -04:00
|
|
|
import re
|
|
|
|
import requests
|
2018-05-09 10:12:02 -04:00
|
|
|
|
2018-05-14 11:23:25 -04:00
|
|
|
from common import *
|
2018-05-09 10:12:02 -04:00
|
|
|
|
2018-06-01 13:56:46 -04:00
|
|
|
def getStrings(targetIP):
|
2018-05-14 22:37:17 -04:00
|
|
|
"""Parses out the message strings from source."""
|
2018-06-01 13:56:46 -04:00
|
|
|
r = requests.get('https://' + targetIP + '/html/en_EN/en_EN.js',
|
2018-05-14 22:37:17 -04:00
|
|
|
auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD),
|
|
|
|
verify=False)
|
|
|
|
regex = re.compile(r'([0-9]+)="([^"]*)')
|
|
|
|
strings = [regex.search(s) for s in r.text.split(';')
|
|
|
|
if s.startswith('localeStrings.eventDetails')]
|
|
|
|
print({int(g.group(1)): g.group(2) for g in strings})
|
|
|
|
|
2018-06-01 13:56:46 -04:00
|
|
|
def getMessages(doorName, doorIP):
|
2018-06-01 13:51:50 -04:00
|
|
|
# get parameters for messages to get?
|
|
|
|
# honestly not really sure why this is required, their API is confusing
|
2018-08-16 12:52:25 -04:00
|
|
|
parXMLIn = E_plain.VertXMessage(
|
|
|
|
E.EventMessages({"action": "LR"}))
|
|
|
|
parXMLOut = doXMLRequest(doorIP, parXMLIn)
|
|
|
|
etree.dump(parXMLOut)
|
2018-05-09 10:12:02 -04:00
|
|
|
|
2018-06-01 13:56:46 -04:00
|
|
|
if os.path.exists("logs/" + doorName + ".xml"):
|
2018-06-01 13:51:50 -04:00
|
|
|
# read last log
|
2018-08-16 12:52:25 -04:00
|
|
|
tree = etree.ElementTree(file="logs/" + doorName + ".xml")
|
2018-06-01 13:51:50 -04:00
|
|
|
root = tree.getroot()
|
|
|
|
recordCount = int(parXMLOut[0].attrib["historyRecordMarker"]) - \
|
|
|
|
int(root[0][0].attrib["recordMarker"])
|
|
|
|
else:
|
|
|
|
# first run for this door
|
2018-06-01 13:56:46 -04:00
|
|
|
root = None
|
2018-06-01 13:51:50 -04:00
|
|
|
recordCount = 1000
|
2018-05-27 17:44:00 -04:00
|
|
|
|
2018-06-01 13:56:46 -04:00
|
|
|
if recordCount == 0:
|
|
|
|
print("No records to get!")
|
|
|
|
return
|
2018-06-01 13:51:50 -04:00
|
|
|
print("Getting", recordCount, "records")
|
|
|
|
# get the actual messages
|
2018-08-16 12:52:25 -04:00
|
|
|
eventsXMLIn = E_plain.VertXMessage(
|
|
|
|
E.EventMessages({"action": "LR",
|
|
|
|
"recordCount": str(recordCount),
|
|
|
|
"historyRecordMarker": parXMLOut[0].attrib["historyRecordMarker"],
|
|
|
|
"historyTimestamp": parXMLOut[0].attrib["historyTimestamp"]}))
|
|
|
|
eventsXMLOut = doXMLRequest(doorIP, eventsXMLIn)
|
2018-06-01 13:51:50 -04:00
|
|
|
#TODO: handle modeRecords=true
|
2018-05-27 17:44:00 -04:00
|
|
|
|
2018-06-01 13:51:50 -04:00
|
|
|
for index, event in enumerate(eventsXMLOut[0]):
|
|
|
|
event.attrib["recordMarker"] = str(int(parXMLOut[0].attrib["historyRecordMarker"]) - index)
|
2018-05-14 22:41:10 -04:00
|
|
|
|
2018-06-01 13:51:50 -04:00
|
|
|
if root is None:
|
2018-08-16 12:52:25 -04:00
|
|
|
tree = etree.ElementTree(eventsXMLOut)
|
2018-06-01 13:51:50 -04:00
|
|
|
else:
|
|
|
|
for event in reversed(eventsXMLOut[0]):
|
|
|
|
root[0].insert(0, event)
|
2018-06-01 13:56:46 -04:00
|
|
|
tree.write("logs/" + doorName + ".xml")
|
|
|
|
|
|
|
|
def main():
|
|
|
|
for doorName, doorData in config["doors"].items():
|
|
|
|
getMessages(doorName, doorData["ip"])
|
2018-06-01 13:51:50 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|