forked from CMS/memberPlumbing
Make executable, clean up style, and rename new door updater
This commit is contained in:
parent
21a9aa5b5c
commit
2b894d3cc9
21
new_xml_based.py → doorUpdater.py
Normal file → Executable file
21
new_xml_based.py → doorUpdater.py
Normal file → Executable file
@ -1,11 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import requests
|
|
||||||
from lxml import etree
|
|
||||||
|
|
||||||
from common import doors, getMembershipworksData, memberLevels
|
from common import doors, getMembershipworksData, memberLevels
|
||||||
from hid.DoorController import E, ROOT
|
from hid.DoorController import E, ROOT
|
||||||
from hid.Credential import Credential
|
from hid.Credential import Credential
|
||||||
|
|
||||||
|
|
||||||
class Member():
|
class Member():
|
||||||
def __init__(self, forename, surname, membershipWorksID,
|
def __init__(self, forename, surname, membershipWorksID,
|
||||||
middleName="", email="", phone="",
|
middleName="", email="", phone="",
|
||||||
@ -129,9 +128,10 @@ def update_door(door, members):
|
|||||||
allCredentials = set(Credential(hex=c.attrib['rawCardNumber'])
|
allCredentials = set(Credential(hex=c.attrib['rawCardNumber'])
|
||||||
for c in door.get_credentials())
|
for c in door.get_credentials())
|
||||||
|
|
||||||
for member in members:
|
|
||||||
# TODO: can I combine requests?
|
# TODO: can I combine requests?
|
||||||
if member.membershipWorksID in cardholders: # cardholder exists, compare contents
|
for member in members:
|
||||||
|
# cardholder exists, compare contents
|
||||||
|
if member.membershipWorksID in cardholders:
|
||||||
ch = cardholders.pop(member.membershipWorksID)
|
ch = cardholders.pop(member.membershipWorksID)
|
||||||
member.cardholderID = ch.cardholderID
|
member.cardholderID = ch.cardholderID
|
||||||
if member.attribs() != ch.attribs(): # update cardholder attributes
|
if member.attribs() != ch.attribs(): # update cardholder attributes
|
||||||
@ -179,25 +179,28 @@ def update_door(door, members):
|
|||||||
door.doXMLRequest(ROOT(member.make_credentials(
|
door.doXMLRequest(ROOT(member.make_credentials(
|
||||||
newCards - allCredentials, cardFormats)))
|
newCards - allCredentials, cardFormats)))
|
||||||
|
|
||||||
|
|
||||||
if member.schedulesForDoor(door) != ch.schedules:
|
if member.schedulesForDoor(door) != ch.schedules:
|
||||||
print("- Updating schedule for" +
|
print("- Updating schedule for" +
|
||||||
f" {member.forename} {member.surname}:" +
|
f" {member.forename} {member.surname}:" +
|
||||||
f" {ch.schedules} -> {member.schedulesForDoor(door)}")
|
f" {ch.schedules} -> {member.schedulesForDoor(door)}")
|
||||||
door.doXMLRequest(ROOT(member.make_schedules(door, schedulesMap)))
|
door.doXMLRequest(ROOT(
|
||||||
|
member.make_schedules(door, schedulesMap)))
|
||||||
else: # cardholder did not exist, so add them
|
else: # cardholder did not exist, so add them
|
||||||
print(f"- Adding Member:")
|
print(f"- Adding Member:")
|
||||||
print(member)
|
print(member)
|
||||||
resp = door.doXMLRequest(ROOT(
|
resp = door.doXMLRequest(ROOT(
|
||||||
E.Cardholders({"action": "AD"},
|
E.Cardholders(
|
||||||
|
{"action": "AD"},
|
||||||
E.Cardholder(member.attribs()))))
|
E.Cardholder(member.attribs()))))
|
||||||
member.cardholderID = resp.find('{*}Cardholders/{*}Cardholder') \
|
member.cardholderID = resp.find('{*}Cardholders/{*}Cardholder') \
|
||||||
.attrib["cardholderID"]
|
.attrib["cardholderID"]
|
||||||
door.doXMLRequest(ROOT(member.make_credentials(member.credentials, cardFormats),
|
door.doXMLRequest(ROOT(
|
||||||
|
member.make_credentials(member.credentials, cardFormats),
|
||||||
member.make_schedules(door, schedulesMap)))
|
member.make_schedules(door, schedulesMap)))
|
||||||
|
|
||||||
# TODO: delete cardholders that are no longer members?
|
# TODO: delete cardholders that are no longer members?
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
memberData = getMembershipworksData(
|
memberData = getMembershipworksData(
|
||||||
['members', 'staff', 'misc'],
|
['members', 'staff', 'misc'],
|
||||||
@ -209,4 +212,6 @@ def main():
|
|||||||
print(door.name, door.ip)
|
print(door.name, door.ip)
|
||||||
update_door(door, members)
|
update_door(door, members)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user