diff --git a/hid/DoorController.py b/hid/DoorController.py index c1aa7bc..d7d1e85 100644 --- a/hid/DoorController.py +++ b/hid/DoorController.py @@ -125,18 +125,32 @@ class DoorController(): E.FixedField({"value": str(facilityCode)})))) return self.doXMLRequest(el) + def get_records(self, req, count, params={}): + result = [] + recordCount = 0 + moreRecords = True + + while moreRecords: + res = self.doXMLRequest(ROOT( + req({ + "action": "LR", + "recordCount": str(count - recordCount), + "recordOffset": str(recordCount), + **params + }))) + result += list(res[0]) + + recordCount += int(res[0].get('recordCount')) + moreRecords = res[0].get('moreRecords') == 'true' + + return result + def get_cardholders(self): - return self.doXMLRequest( - ROOT(E.Cardholders({"action": "LR", - "responseFormat": "expanded", - "recordOffset": "0", - "recordCount": "1000"})))[0] + return self.get_records(E.Cardholders, 1000, + {"responseFormat": "expanded"}) def get_credentials(self): - return self.doXMLRequest( - ROOT(E.Credentials({"action": "LR", - "recordOffset": "0", - "recordCount": "1000"})))[0] + return self.get_records(E.Credentials, 1000) def get_lock(self): el = ROOT(