Switch config file from JSON to YAML

This commit is contained in:
Adam Goldsmith 2019-12-20 18:42:06 -05:00
parent d248e41fdb
commit d5be64c37d
3 changed files with 24 additions and 22 deletions

View File

@ -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

View File

@ -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"}
}
}

16
config.yaml Normal file
View File

@ -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