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
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()