buypeeb/settings.py

37 lines
1,016 B
Python
Raw Normal View History

import json, os
from os import path
import functions
from listing import YahooAuctionsItem
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.s['watchlist'] = []
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.update(json.load(open(self.location + "config.json", 'r')))
except:
print("Couldn't load settings - using defaults")
2020-08-21 10:35:53 +00:00
def get(self, setting: str): # javalicious
return self.s.get(setting, None)
def set(self, setting: str, value):
self.s['setting'] = value
def watch(self, name: string, url: string):
self.s['watchlist'].add(YahooAuctionsItem(name, url))