From d5be64c37d6457a4406f6cf0ef55501787712225 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 20 Dec 2019 18:42:06 -0500 Subject: [PATCH] Switch config file from JSON to YAML --- common.py | 20 ++++++++------------ config.json | 10 ---------- config.yaml | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 22 deletions(-) delete mode 100644 config.json create mode 100644 config.yaml diff --git a/common.py b/common.py index b6e35c3..7aa1861 100644 --- a/common.py +++ b/common.py @@ -1,5 +1,5 @@ import csv -import json +from ruamel.yaml import YAML import urllib3 import os import sys @@ -7,29 +7,25 @@ from io import StringIO import requests from hid.DoorController import DoorController -from passwords import * +from passwords import (DOOR_USERNAME, DOOR_PASSWORD, + MEMBERSHIPWORKS_USERNAME, MEMBERSHIPWORKS_PASSWORD) # it's fine, ssl certs are for losers anyway urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) try: - config = json.load( - open(os.path.dirname(os.path.abspath(__file__)) + "/config.json")) + with open(os.path.dirname(os.path.abspath(__file__)) + "/config.yaml") as f: + config = YAML().load(f) except NameError: - config = json.load(open("config.json")) + with open("config.yaml") as f: + config = YAML().load(f) doors = {doorName: DoorController(doorData['ip'], DOOR_USERNAME, DOOR_PASSWORD, name=doorName, access=doorData['access']) for doorName, doorData in config["doors"].items()} -# mapping of member levels to schedules -memberLevels = {"CMS Staff": "7x24", - "CMS Weekends Only": "Weekends Only", - "CMS Weekdays Only": "Weekdays Only", - "CMS Unlimited": "Unlimited", - "CMS Nights & Weekends": "Nights and Weekends", - "CMS Day Pass": "Unlimited"} +memberLevels = config['memberLevels'] def getMembershipworksData(folders, columns): """ Pull the members csv from the membershipworks api diff --git a/config.json b/config.json deleted file mode 100644 index 2afbb31..0000000 --- a/config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "doors": { - "Studio Space": {"ip": "172.18.51.11", "access": "Studio Space"}, - "Front Door": {"ip": "172.18.51.12", "access": "Front Door"}, - "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"}, - "Storage Closet": {"ip": "172.18.51.16", "access": "Storage Closet"} - } -} diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..1f91825 --- /dev/null +++ b/config.yaml @@ -0,0 +1,16 @@ +doors: + Studio Space: {ip: 172.18.51.11, access: Studio Space} + Front Door: {ip: 172.18.51.12, access: Front Door} + 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} + Storage Closet: {ip: 172.18.51.16, access: Storage Closet} + +# {member type: door schedule} +memberLevels: + CMS Staff: 7x24 + CMS Weekends Only: Weekends Only + CMS Weekdays Only: Weekdays Only + CMS Unlimited: Unlimited + CMS Nights & Weekends: Nights and Weekends + CMS Day Pass: Unlimited