doorUpdater: Retrieve former members and remove their schedules

This commit is contained in:
Adam Goldsmith 2020-03-29 00:15:54 -04:00
parent 952852badb
commit cf84086446

View File

@ -9,7 +9,7 @@ from lib.hid.DoorController import ROOT, E
class Member(): class Member():
def __init__(self, forename="", surname="", membershipWorksID="", def __init__(self, forename="", surname="", membershipWorksID="",
middleName="", email="", phone="", middleName="", email="", phone="",
cardholderID=None, doorAccess=[], onHold=False, cardholderID=None, doorAccess=[],
credentials=set(), levels=[], extraLevels=[], schedules=[]): credentials=set(), levels=[], extraLevels=[], schedules=[]):
self.forename = forename self.forename = forename
self.surname = surname self.surname = surname
@ -19,19 +19,17 @@ class Member():
self.phone = phone self.phone = phone
self.cardholderID = cardholderID self.cardholderID = cardholderID
self.doorAccess = doorAccess self.doorAccess = doorAccess
self.onHold = onHold
self.credentials = credentials self.credentials = credentials
self.levels = levels self.levels = levels
self.schedules = schedules self.schedules = schedules
def __repr__(self): def __str__(self):
return f"""Name: {self.forename} | {self.middleName} | {self.surname} return f"""Name: {self.forename} | {self.middleName} | {self.surname}
MembershipWorks ID: {self.membershipWorksID} MembershipWorks ID: {self.membershipWorksID}
Email: {self.email} Email: {self.email}
Phone: {self.phone} Phone: {self.phone}
Cardholder ID: {self.cardholderID} Cardholder ID: {self.cardholderID}
doorAccess: {self.doorAccess} doorAccess: {self.doorAccess}
On Hold? {self.onHold}
Credentials: {self.credentials} Credentials: {self.credentials}
Levels: {self.levels} Levels: {self.levels}
Schedules: {self.schedules} Schedules: {self.schedules}
@ -39,13 +37,12 @@ Schedules: {self.schedules}
class MembershipworksMember(Member): class MembershipworksMember(Member):
def __init__(self, data): def __init__(self, data, formerMember=False):
super().__init__(data["First Name"], super().__init__(data["First Name"],
data["Last Name"], data["Last Name"],
membershipWorksID=data["Account ID"], membershipWorksID=data["Account ID"],
email=data["Email"], email=data["Email"],
phone=data["Phone"], phone=data["Phone"])
onHold=data["Account on Hold"] != "")
if data["Access Card Number"] != "": if data["Access Card Number"] != "":
self.credentials = set([Credential( self.credentials = set([Credential(
@ -54,6 +51,10 @@ class MembershipworksMember(Member):
else: else:
self.credentials = set() self.credentials = set()
self.onHold=data["Account on Hold"] != ""
self.limitedOperations=data['Access Permitted During Limited Operations'] == "Y"
self.formerMember=formerMember
levels = {k: v for k, v in memberLevels.items() if data[k] == k} levels = {k: v for k, v in memberLevels.items() if data[k] == k}
self.levels = list(levels.keys()) self.levels = list(levels.keys())
self.schedules = list(levels.values()) self.schedules = list(levels.values())
@ -68,24 +69,38 @@ class MembershipworksMember(Member):
self.doorAccess = [ self.doorAccess = [
door for door, doorData in doors.items() door for door, doorData in doors.items()
if data["Access " + doorData.access + "?"] == "Y" if data["Access " + doorData.access + "?"] == "Y"
and data['Access Permitted During Limited Operations'] == "Y"
] ]
def to_DoorMember(self, door): def to_DoorMember(self, door):
doorLevels = [k for k, v in self.extraLevels.items() if door.name in v] doorLevels = [k for k, v in self.extraLevels.items() if door.name in v]
if door.name not in self.doorAccess or self.onHold: if (door.name not in self.doorAccess
or self.onHold
or self.formerMember
or not self.limitedOperations):
schedules = [] schedules = []
else: else:
schedules = self.schedules + doorLevels schedules = self.schedules + doorLevels
dm = DoorMember(door, **self.__dict__) # this is probably terrible dm = DoorMember(door,
dm.levels = self.levels + doorLevels forename=self.forename,
dm.schedules = schedules surname=self.surname,
membershipWorksID=self.membershipWorksID,
email=self.email,
phone=self.phone,
levels=self.levels + doorLevels,
doorAccess=self.doorAccess,
credentials=self.credentials,
schedules=schedules)
return dm return dm
def __str__(self):
return super().__str__() + f"""OnHold? {self.onHold}
Limited Operations Access? {self.limitedOperations}
Former Member? {self.formerMember}
"""
class DoorMember(Member): class DoorMember(Member):
def __init__(self, door, *args, **kwargs): def __init__(self, door, *args, **kwargs):
@ -236,12 +251,31 @@ def update_door(door, members):
def main(): def main():
memberData = membershipworks.get_members( membershipworks_attributes = \
['Members', 'CMS Staff', 'Misc. Access'], "_id,nam,phn,eml,lvl,lbl,xws,xms,xsc,xas,xfd,xac,xcf,xeh,xse,xlo"
"_id,nam,phn,eml,lvl,lbl,xws,xms,xsc,xas,xfd,xac,xcf,xeh,xse,xlo")
memberData = membershipworks.get_members(
['Members', 'CMS Staff', 'Misc. Access'], membershipworks_attributes)
members = [MembershipworksMember(m) for m in memberData] members = [MembershipworksMember(m) for m in memberData]
formerMemberData = membershipworks.get_members(
['Former Members'], membershipworks_attributes)
formerMembers = [MembershipworksMember(m, formerMember=True)
for m in formerMemberData]
for formerMember in formerMembers:
member = next(
(m for m in members
if m.membershipWorksID == formerMember.membershipWorksID),
None)
# member exists in another folder
if member is not None:
member.formerMember = True
else: # member is only a former member
formerMember.formerMember = True
members.append(formerMember)
for door in doors.values(): for door in doors.values():
print(door.name, door.ip) print(door.name, door.ip)
update_door(door, members) update_door(door, members)