From 4a0df699c8f3f15750cea9290854019f4eacc64a Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sun, 3 Jun 2018 14:24:46 -0400 Subject: [PATCH] doorUpdater: Update hashes for each door as they complete instead of all at once --- doorUpdater.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/doorUpdater.py b/doorUpdater.py index f8eb0dc..444802e 100755 --- a/doorUpdater.py +++ b/doorUpdater.py @@ -85,7 +85,7 @@ def makeMember(member, doorAuth): return out -def makeDoor(doorName, doorData, members, prevHash): +def makeDoor(doorName, doorData, members, hashes): """Create a CSV for the given door""" outString = StringIO() writer = csv.DictWriter(outString, fieldnames) @@ -99,12 +99,14 @@ def makeDoor(doorName, doorData, members, prevHash): outString.seek(0) doorHash = md5(bytes(outString.getvalue(), 'utf8')).hexdigest() - if doorHash == prevHash: + if doorHash == hashes.get(doorName): print("Door", doorName, "not changed, not updating") else: + hashes[doorName] = doorHash doCSVImport(doorData["ip"], outString) - - return doorHash + # write out hash if we sucessfully updated this door + with open('/tmp/doorUpdaterLastHash', 'w') as f: + json.dump(hashes, f) def main(): data = getMembershipworksData() @@ -119,12 +121,7 @@ def main(): for doorName, doorData in config["doors"].items(): print(doorName, doorData) - hashes[doorName] = makeDoor(doorName, doorData, members, - hashes.get(doorName, "")) - - # write out hash if we sucessfully got here - with open('/tmp/doorUpdaterLastHash', 'w') as f: - json.dump(hashes, f) + makeDoor(doorName, doorData, members, hashes) if __name__ == '__main__': main()