forked from CMS/memberPlumbing
doorUpdater: Update hashes for each door as they complete
instead of all at once
This commit is contained in:
parent
8e82caea0f
commit
4a0df699c8
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user