diff --git a/common.py b/common.py index 49e0f19..3665e61 100644 --- a/common.py +++ b/common.py @@ -1,3 +1,4 @@ +import json import urllib3 from xml.etree import ElementTree as ET import requests @@ -7,6 +8,8 @@ from passwords import * # it's fine, ssl certs are for losers anyway urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +config = json.load(open("config.json")) + ET.register_namespace("hid", "http://www.hidglobal.com/VertX") ET.register_namespace("hid", "http://www.hidcorp.com/VertX") diff --git a/config.json b/config.json new file mode 100644 index 0000000..4122deb --- /dev/null +++ b/config.json @@ -0,0 +1,9 @@ +{ + "doors": { + "Rental Studio": {"ip": "172.18.51.11", "access": "Rental Studio"}, + "Storage Closet": {"ip": "172.18.51.12", "access": "Storage Closet"}, + "Metal Shop": {"ip": "172.18.51.13", "access": "Metal Shop"}, + "Wood Shop": {"ip": "172.18.51.14", "access": "Wood Shop"}, + "Wood Shop Rear": {"ip": "172.18.51.15", "access": "Wood Shop"} + } +} diff --git a/doorUpdater.py b/doorUpdater.py index 14343f9..e508a17 100755 --- a/doorUpdater.py +++ b/doorUpdater.py @@ -15,15 +15,6 @@ memberLevels = {"CMS Staff": "7x24", "CMS Unlimited": "Unlimited", "CMS Nights & Weekends": "Nights and Weekends"} -# door access permissions to controller IP addresses -doors = { - "Rental Studio": ["172.18.51.11"], - "Storage Closet": ["172.18.51.12"], - "Metal Shop": ["172.18.51.13"], - "Wood Shop": ["172.18.51.14", "172.18.51.15"] -} - - def getMembershipworksData(): """ Pull the members csv from the membershipworks api """ BASE_URL = "https://api.membershipworks.com/v1/" @@ -103,29 +94,30 @@ def makeMember(member, doorAuth): return out -def makeDoor(doorName, doorIPs, members): +def makeDoor(doorName, doorData, members): """Create a CSV for the given door""" outString = StringIO() writer = csv.DictWriter(outString, fieldnames) writer.writeheader() for member in members: - member = makeMember(member, "Access " + doorName + "?") + member = makeMember(member, "Access " + doorData["access"] + "?") if member is not None: writer.writerow(member) print(outString.getvalue()) - for doorIP in doorIPs: - outString.seek(0) - doCSVImport(doorIP, outString) - pass + + outString.seek(0) + doCSVImport(doorData["ip"], outString) + pass def main(): data, newHash = getMembershipworksData() reader = csv.DictReader(StringIO(data)) members = list(reader) - for doorName, doorIP in doors.items(): - makeDoor(doorName, doorIP, members) + for doorName, doorData in config["doors"].items(): + print(doorName, doorData) + makeDoor(doorName, doorData, members) # write out hash if we sucessfully got here with open('/tmp/doorUpdaterLastHash', 'w') as f: