forked from CMS/memberPlumbing
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)
|
print(r.text)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
newHash = md5(bytes(r.text, 'utf8')).hexdigest()
|
return r.text
|
||||||
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
|
|
||||||
|
|
||||||
def makeMember(member, doorAuth):
|
def makeMember(member, doorAuth):
|
||||||
"""Create an output CSV row for the member"""
|
"""Create an output CSV row for the member"""
|
||||||
@ -92,7 +85,7 @@ def makeMember(member, doorAuth):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def makeDoor(doorName, doorData, members):
|
def makeDoor(doorName, doorData, members, prevHash):
|
||||||
"""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)
|
||||||
@ -105,21 +98,33 @@ def makeDoor(doorName, doorData, members):
|
|||||||
print(outString.getvalue())
|
print(outString.getvalue())
|
||||||
|
|
||||||
outString.seek(0)
|
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)
|
doCSVImport(doorData["ip"], outString)
|
||||||
pass
|
|
||||||
|
return doorHash
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
data, newHash = getMembershipworksData()
|
data = getMembershipworksData()
|
||||||
reader = csv.DictReader(StringIO(data))
|
reader = csv.DictReader(StringIO(data))
|
||||||
members = list(reader)
|
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():
|
for doorName, doorData in config["doors"].items():
|
||||||
print(doorName, doorData)
|
print(doorName, doorData)
|
||||||
makeDoor(doorName, doorData, members)
|
hashes[doorName] = makeDoor(doorName, doorData, members,
|
||||||
|
hashes.get(doorName, ""))
|
||||||
|
|
||||||
# write out hash if we sucessfully got here
|
# write out hash if we sucessfully got here
|
||||||
with open('/tmp/doorUpdaterLastHash', 'w') as f:
|
with open('/tmp/doorUpdaterLastHash', 'w') as f:
|
||||||
f.write(newHash)
|
json.dump(hashes, f)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user