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