2020-08-21 10:32:43 +00:00
|
|
|
import json, os
|
|
|
|
from os import path
|
|
|
|
|
2020-08-21 10:52:40 +00:00
|
|
|
import functions
|
|
|
|
from listing import YahooAuctionsItem
|
|
|
|
|
2020-08-21 10:32:43 +00:00
|
|
|
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
|
2020-08-21 10:52:40 +00:00
|
|
|
self.s['watchlist'] = []
|
2020-08-21 10:32:43 +00:00
|
|
|
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:
|
2020-08-21 10:52:40 +00:00
|
|
|
self.s.update(json.load(open(self.location + "config.json", 'r')))
|
2020-08-21 10:32:43 +00:00
|
|
|
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
|
2020-08-21 10:52:40 +00:00
|
|
|
|
2020-08-21 10:59:35 +00:00
|
|
|
def watch(self, name: str, url: str):
|
2020-08-21 10:52:40 +00:00
|
|
|
self.s['watchlist'].add(YahooAuctionsItem(name, url))
|