forked from CMS/memberPlumbing
Merge XML requests into common.py
This commit is contained in:
parent
5f30998131
commit
8a63c64917
15
common.py
15
common.py
@ -32,3 +32,18 @@ def doCSVImport(doorIP, csv):
|
||||
{"task": "importCardsPeople", "name": "cardspeopleschedule.csv"},
|
||||
{"importCardsPeopleButton": ("cardspeopleschedule.csv", csv, 'text/csv')})
|
||||
doImportRequest(doorIP, {"task": "importDone"})
|
||||
|
||||
def doXMLRequest(doorIP, xml, prefix=b'<?xml version="1.0" encoding="UTF-8"?>'):
|
||||
r = requests.get(
|
||||
'https://' + doorIP + '/cgi-bin/vertx_xml.cgi',
|
||||
params={'XML': prefix + xml},
|
||||
auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD),
|
||||
verify=False)
|
||||
xml = ET.XML(r.text)
|
||||
# probably meed to be more sane about this
|
||||
if r.status_code != 200 \
|
||||
or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0:
|
||||
print("Door Updating Error: ", r.status_code, r.reason)
|
||||
print(r.text)
|
||||
sys.exit(1)
|
||||
return xml
|
||||
|
20
events.py
20
events.py
@ -1,12 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
import requests
|
||||
from xml.etree import ElementTree as ET
|
||||
import urllib3
|
||||
|
||||
from passwords import *
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
from common import *
|
||||
|
||||
TARGET_IP = '172.18.51.11'
|
||||
|
||||
# From /html/en_EN/en_EN.js localeStrings
|
||||
eventStrings = {
|
||||
@ -36,22 +33,13 @@ eventStrings = {
|
||||
4045: 'Battery Failure',
|
||||
}
|
||||
|
||||
def doRequest(xml):
|
||||
r = requests.get(
|
||||
'https://172.18.51.11/cgi-bin/vertx_xml.cgi',
|
||||
params={'XML': b'<?xml version="1.0" encoding="UTF-8"?>' + xml},
|
||||
auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD),
|
||||
verify=False)
|
||||
return ET.XML(r.text)
|
||||
|
||||
|
||||
#<?xml version="1.0" encoding="UTF-8"?> <VertXMessage> <hid:EventMessages action="LR" recordCount="100" historyRecordMarker="463" historyTimestamp="1525824431"/> </VertXMessage>
|
||||
|
||||
#<?xml version="1.0" encoding="UTF-8"?><VertXMessage xmlns:hid="http://www.hidcorp.com/VertX"><hid:EventMessages action="RL" historyRecordMarker="463" historyTimestamp="1525824431" currentRecordMarker="463" currentTimestamp="1525824431" /></VertXMessage>
|
||||
|
||||
XML = ET.Element("VertXMessage")
|
||||
ET.SubElement(XML, "hid:EventMessages", attrib={"action": "LR"})
|
||||
xml = doRequest(ET.tostring(XML))
|
||||
xml = doXMLRequest(TARGET_IP, ET.tostring(XML))
|
||||
print(xml[0].attrib)
|
||||
|
||||
XML = ET.Element("VertXMessage")
|
||||
@ -60,7 +48,7 @@ ET.SubElement(XML, "hid:EventMessages",
|
||||
"recordCount": "1000",
|
||||
"historyRecordMarker": xml[0].attrib["historyRecordMarker"],
|
||||
"historyTimestamp": xml[0].attrib["historyTimestamp"]})
|
||||
xml = doRequest(ET.tostring(XML))
|
||||
xml = doXMLRequest(TARGET_IP, ET.tostring(XML))
|
||||
for event in xml[0]:
|
||||
ET.dump(event)
|
||||
att = event.attrib
|
||||
|
@ -8,14 +8,6 @@ from common import *
|
||||
|
||||
TARGET_IP = '172.18.51.15'
|
||||
|
||||
def doRequest(xml):
|
||||
r = requests.get(
|
||||
'https://' + TARGET_IP + '/cgi-bin/vertx_xml.cgi',
|
||||
params={'XML': xml},
|
||||
auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD),
|
||||
verify=False)
|
||||
print(r.text)
|
||||
|
||||
# clear all people
|
||||
outString = StringIO()
|
||||
writer = csv.DictWriter(outString, fieldnames)
|
||||
@ -29,8 +21,7 @@ delXML = ET.Element("VertXMessage")
|
||||
for ii in range(1, 8):
|
||||
ET.SubElement(delXML, "hid:Schedules",
|
||||
attrib={"action": "DD", "scheduleID": str(ii)})
|
||||
print(b'<?xml version="1.0" encoding="UTF-8"?>' + ET.tostring(delXML))
|
||||
doRequest(b'<?xml version="1.0" encoding="UTF-8"?>' + ET.tostring(delXML))
|
||||
doXMLRequest(TARGET_IP, ET.tostring(delXML))
|
||||
|
||||
# load new schedules
|
||||
with open("schedules.xml", "rb") as f:
|
||||
|
Loading…
Reference in New Issue
Block a user