buypeeb/settings.py

30 lines
823 B
Python

import json, os
from os import path
class BuypeebSettings:
def __init__(self, location: str):
self.s = {}
self.s['updateInterval'] = 10 * 60
self.s['favouriteUpdateInterval'] = 5 * 60
self.s['updateIntervalCritical'] = 60
self.s['favouriteUpdateIntervalCritical'] = 30
self.location = location
def save(self):
json.dump(self.s, open(self.location + "config.json", 'w'))
def load(self):
if not path.isfile(self.location + "config.json"):
os.makedirs(self.location, 0o755)
open(self.location + "config.json", 'x')
try:
self.s = json.load(open(self.location + "config.json", 'r'))
except:
print("Couldn't load settings - using defaults")
def get(self, setting: str): # javalicious
return self.s.get(setting, None)
def set(self, setting: str, value):
self.s['setting'] = value