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