From 82e9a9b0377ee3af38d6ec53c86ebdde361e152a Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 11 May 2018 19:03:29 -0400 Subject: [PATCH] Only write out hash if doorUpdater gets to the end of main --- doorUpdater.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doorUpdater.py b/doorUpdater.py index 213a030..b09f0c4 100755 --- a/doorUpdater.py +++ b/doorUpdater.py @@ -77,10 +77,8 @@ def getMembershipworksData(): if newHash == f.read(): print("hashes are the same, not updating") sys.exit(0) - with open('/tmp/doorUpdaterLastHash', 'w') as f: - f.write(newHash) - return r.text + return r.text, newHash def makeMember(member, doorAuth): """Create an output CSV row for the member""" @@ -149,12 +147,16 @@ def makeDoor(doorName, doorIPs, members): pass def main(): - data = getMembershipworksData() + data, newHash = getMembershipworksData() reader = csv.DictReader(StringIO(data)) members = list(reader) for doorName, doorIP in doors.items(): makeDoor(doorName, doorIP, members) + # write out hash if we sucessfully got here + with open('/tmp/doorUpdaterLastHash', 'w') as f: + f.write(newHash) + if __name__ == '__main__': main()