doorUpdater: Update hashes for each door as they complete

instead of all at once
This commit is contained in:
Adam Goldsmith 2018-06-03 14:24:46 -04:00
parent 8e82caea0f
commit 4a0df699c8

View File

@ -85,7 +85,7 @@ def makeMember(member, doorAuth):
return out return out
def makeDoor(doorName, doorData, members, prevHash): def makeDoor(doorName, doorData, members, hashes):
"""Create a CSV for the given door""" """Create a CSV for the given door"""
outString = StringIO() outString = StringIO()
writer = csv.DictWriter(outString, fieldnames) writer = csv.DictWriter(outString, fieldnames)
@ -99,12 +99,14 @@ def makeDoor(doorName, doorData, members, prevHash):
outString.seek(0) outString.seek(0)
doorHash = md5(bytes(outString.getvalue(), 'utf8')).hexdigest() doorHash = md5(bytes(outString.getvalue(), 'utf8')).hexdigest()
if doorHash == prevHash: if doorHash == hashes.get(doorName):
print("Door", doorName, "not changed, not updating") print("Door", doorName, "not changed, not updating")
else: else:
hashes[doorName] = doorHash
doCSVImport(doorData["ip"], outString) doCSVImport(doorData["ip"], outString)
# write out hash if we sucessfully updated this door
return doorHash with open('/tmp/doorUpdaterLastHash', 'w') as f:
json.dump(hashes, f)
def main(): def main():
data = getMembershipworksData() data = getMembershipworksData()
@ -119,12 +121,7 @@ def main():
for doorName, doorData in config["doors"].items(): for doorName, doorData in config["doors"].items():
print(doorName, doorData) print(doorName, doorData)
hashes[doorName] = makeDoor(doorName, doorData, members, makeDoor(doorName, doorData, members, hashes)
hashes.get(doorName, ""))
# write out hash if we sucessfully got here
with open('/tmp/doorUpdaterLastHash', 'w') as f:
json.dump(hashes, f)
if __name__ == '__main__': if __name__ == '__main__':
main() main()