sendSchedule: Add clearing people DB

allows updating doors fully automatically
This commit is contained in:
Adam Goldsmith 2018-05-12 09:50:12 -04:00
parent 33c0857e1b
commit 0d95865c8b

View File

@ -1,20 +1,30 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import requests import requests
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
import urllib3 import csv
from io import StringIO
from passwords import * from common import *
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) TARGET_IP = '172.18.51.15'
def doRequest(xml): def doRequest(xml):
r = requests.get( r = requests.get(
'https://172.18.51.15/cgi-bin/vertx_xml.cgi', 'https://' + TARGET_IP + '/cgi-bin/vertx_xml.cgi',
params={'XML': xml}, params={'XML': xml},
auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD), auth=requests.auth.HTTPDigestAuth(DOOR_USERNAME, DOOR_PASSWORD),
verify=False) verify=False)
print(r.text) print(r.text)
# clear all people
outString = StringIO()
writer = csv.DictWriter(outString, fieldnames)
writer.writeheader()
writer.writerow({})
outString.seek(0)
doCSVImport(TARGET_IP, outString)
# clear all schedules
delXML = ET.Element("VertXMessage") delXML = ET.Element("VertXMessage")
for ii in range(1, 8): for ii in range(1, 8):
ET.SubElement(delXML, "hid:Schedules", ET.SubElement(delXML, "hid:Schedules",
@ -22,5 +32,6 @@ for ii in range(1, 8):
print(b'<?xml version="1.0" encoding="UTF-8"?>' + ET.tostring(delXML)) print(b'<?xml version="1.0" encoding="UTF-8"?>' + ET.tostring(delXML))
doRequest(b'<?xml version="1.0" encoding="UTF-8"?>' + ET.tostring(delXML)) doRequest(b'<?xml version="1.0" encoding="UTF-8"?>' + ET.tostring(delXML))
# load new schedules
with open("schedules.xml", "rb") as f: with open("schedules.xml", "rb") as f:
doRequest(f.read()) doRequest(f.read())