forked from CMS/memberPlumbing
Move config into config.json
This commit is contained in:
parent
0fb1b7481b
commit
aad4de1159
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import urllib3
|
import urllib3
|
||||||
from xml.etree import ElementTree as ET
|
from xml.etree import ElementTree as ET
|
||||||
import requests
|
import requests
|
||||||
@ -7,6 +8,8 @@ from passwords import *
|
|||||||
# it's fine, ssl certs are for losers anyway
|
# it's fine, ssl certs are for losers anyway
|
||||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
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.hidglobal.com/VertX")
|
||||||
ET.register_namespace("hid", "http://www.hidcorp.com/VertX")
|
ET.register_namespace("hid", "http://www.hidcorp.com/VertX")
|
||||||
|
|
||||||
|
9
config.json
Normal file
9
config.json
Normal file
@ -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"}
|
||||||
|
}
|
||||||
|
}
|
@ -15,15 +15,6 @@ memberLevels = {"CMS Staff": "7x24",
|
|||||||
"CMS Unlimited": "Unlimited",
|
"CMS Unlimited": "Unlimited",
|
||||||
"CMS Nights & Weekends": "Nights and Weekends"}
|
"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():
|
def getMembershipworksData():
|
||||||
""" Pull the members csv from the membershipworks api """
|
""" Pull the members csv from the membershipworks api """
|
||||||
BASE_URL = "https://api.membershipworks.com/v1/"
|
BASE_URL = "https://api.membershipworks.com/v1/"
|
||||||
@ -103,29 +94,30 @@ def makeMember(member, doorAuth):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def makeDoor(doorName, doorIPs, members):
|
def makeDoor(doorName, doorData, members):
|
||||||
"""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)
|
||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
for member in members:
|
for member in members:
|
||||||
member = makeMember(member, "Access " + doorName + "?")
|
member = makeMember(member, "Access " + doorData["access"] + "?")
|
||||||
if member is not None:
|
if member is not None:
|
||||||
writer.writerow(member)
|
writer.writerow(member)
|
||||||
|
|
||||||
print(outString.getvalue())
|
print(outString.getvalue())
|
||||||
for doorIP in doorIPs:
|
|
||||||
outString.seek(0)
|
outString.seek(0)
|
||||||
doCSVImport(doorIP, outString)
|
doCSVImport(doorData["ip"], outString)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
data, newHash = 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, doorData in config["doors"].items():
|
||||||
makeDoor(doorName, doorIP, members)
|
print(doorName, doorData)
|
||||||
|
makeDoor(doorName, doorData, members)
|
||||||
|
|
||||||
# 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:
|
||||||
|
Loading…
Reference in New Issue
Block a user