doorUpdater: Do hashing on output csvs instead of MembershipWorks input
This commit is contained in:
parent
3df228afd5
commit
71d3f9ecea
@ -56,14 +56,7 @@ def getMembershipworksData():
|
||||
print(r.text)
|
||||
sys.exit(1)
|
||||
|
||||
newHash = md5(bytes(r.text, 'utf8')).hexdigest()
|
||||
if os.path.exists('/tmp/doorUpdaterLastHash'):
|
||||
with open('/tmp/doorUpdaterLastHash', 'r') as f:
|
||||
if newHash == f.read():
|
||||
print("hashes are the same, not updating")
|
||||
sys.exit(0)
|
||||
|
||||
return r.text, newHash
|
||||
return r.text
|
||||
|
||||
def makeMember(member, doorAuth):
|
||||
"""Create an output CSV row for the member"""
|
||||
@ -92,7 +85,7 @@ def makeMember(member, doorAuth):
|
||||
|
||||
return out
|
||||
|
||||
def makeDoor(doorName, doorData, members):
|
||||
def makeDoor(doorName, doorData, members, prevHash):
|
||||
"""Create a CSV for the given door"""
|
||||
outString = StringIO()
|
||||
writer = csv.DictWriter(outString, fieldnames)
|
||||
@ -105,21 +98,33 @@ def makeDoor(doorName, doorData, members):
|
||||
print(outString.getvalue())
|
||||
|
||||
outString.seek(0)
|
||||
doorHash = md5(bytes(outString.getvalue(), 'utf8')).hexdigest()
|
||||
if doorHash == prevHash:
|
||||
print("Door", doorName, "not changed, not updating")
|
||||
else:
|
||||
doCSVImport(doorData["ip"], outString)
|
||||
pass
|
||||
|
||||
return doorHash
|
||||
|
||||
def main():
|
||||
data, newHash = getMembershipworksData()
|
||||
data = getMembershipworksData()
|
||||
reader = csv.DictReader(StringIO(data))
|
||||
members = list(reader)
|
||||
|
||||
if os.path.exists('/tmp/doorUpdaterLastHash'):
|
||||
with open('/tmp/doorUpdaterLastHash', 'r') as f:
|
||||
hashes = json.load(f)
|
||||
else:
|
||||
hashes = {}
|
||||
|
||||
for doorName, doorData in config["doors"].items():
|
||||
print(doorName, doorData)
|
||||
makeDoor(doorName, doorData, members)
|
||||
hashes[doorName] = makeDoor(doorName, doorData, members,
|
||||
hashes.get(doorName, ""))
|
||||
|
||||
# write out hash if we sucessfully got here
|
||||
with open('/tmp/doorUpdaterLastHash', 'w') as f:
|
||||
f.write(newHash)
|
||||
json.dump(hashes, f)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user