68 lines
2.3 KiB
Python
Executable File
68 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from collections import defaultdict
|
|
from lxml import etree
|
|
import os
|
|
import re
|
|
import requests
|
|
|
|
from common import *
|
|
|
|
def getStrings(door):
|
|
"""Parses out the message strings from source."""
|
|
r = requests.get('https://' + door.ip + '/html/en_EN/en_EN.js',
|
|
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})
|
|
|
|
def getMessages(door):
|
|
# get parameters for messages to get?
|
|
# honestly not really sure why this is required, their API is confusing
|
|
parXMLIn = E_plain.VertXMessage(
|
|
E.EventMessages({"action": "LR"}))
|
|
parXMLOut = door.doXMLRequest(parXMLIn)
|
|
etree.dump(parXMLOut)
|
|
|
|
if os.path.exists("logs/" + door.name + ".xml"):
|
|
# read last log
|
|
tree = etree.ElementTree(file="logs/" + door.name + ".xml")
|
|
root = tree.getroot()
|
|
recordCount = int(parXMLOut[0].attrib["historyRecordMarker"]) - \
|
|
int(root[0][0].attrib["recordMarker"])
|
|
else:
|
|
# first run for this door
|
|
root = None
|
|
recordCount = 1000
|
|
|
|
if recordCount == 0:
|
|
print("No records to get!")
|
|
return
|
|
print("Getting", recordCount, "records")
|
|
# get the actual messages
|
|
eventsXMLIn = E_plain.VertXMessage(
|
|
E.EventMessages({"action": "LR",
|
|
"recordCount": str(recordCount),
|
|
"historyRecordMarker": parXMLOut[0].attrib["historyRecordMarker"],
|
|
"historyTimestamp": parXMLOut[0].attrib["historyTimestamp"]}))
|
|
eventsXMLOut = door.doXMLRequest(eventsXMLIn)
|
|
#TODO: handle modeRecords=true
|
|
|
|
for index, event in enumerate(eventsXMLOut[0]):
|
|
event.attrib["recordMarker"] = str(int(parXMLOut[0].attrib["historyRecordMarker"]) - index)
|
|
|
|
if root is None:
|
|
tree = etree.ElementTree(eventsXMLOut)
|
|
else:
|
|
for event in reversed(eventsXMLOut[0]):
|
|
root[0].insert(0, event)
|
|
tree.write("logs/" + doorName + ".xml")
|
|
|
|
def main():
|
|
for door in doors.values():
|
|
getMessages(door)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|