Only write out hash if doorUpdater gets to the end of main

This commit is contained in:
Adam Goldsmith 2018-05-11 19:03:29 -04:00
parent a22de02d3e
commit 82e9a9b037

View File

@ -77,10 +77,8 @@ def getMembershipworksData():
if newHash == f.read(): if newHash == f.read():
print("hashes are the same, not updating") print("hashes are the same, not updating")
sys.exit(0) sys.exit(0)
with open('/tmp/doorUpdaterLastHash', 'w') as f:
f.write(newHash)
return r.text return r.text, newHash
def makeMember(member, doorAuth): def makeMember(member, doorAuth):
"""Create an output CSV row for the member""" """Create an output CSV row for the member"""
@ -149,12 +147,16 @@ def makeDoor(doorName, doorIPs, members):
pass pass
def main(): def main():
data = getMembershipworksData() data, newHash = getMembershipworksData()
reader = csv.DictReader(StringIO(data)) reader = csv.DictReader(StringIO(data))
members = list(reader) members = list(reader)
for doorName, doorIP in doors.items(): for doorName, doorIP in doors.items():
makeDoor(doorName, doorIP, members) 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__': if __name__ == '__main__':
main() main()