From d248e41fdb524c5d40b9698c0ee7befd75364bbd Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 18 Dec 2019 18:42:02 -0500 Subject: [PATCH] Allow DoorController to handle paginated records requests --- hid/DoorController.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) 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(