update the defaults instead of overwriting them in case the settings "schema" has changed between versions

This commit is contained in:
Lynne Megido 2020-08-21 20:52:40 +10:00
parent 1c139f500e
commit 2a3700e6fe
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

View file

@ -1,6 +1,9 @@
import json, os
from os import path
import functions
from listing import YahooAuctionsItem
class BuypeebSettings:
def __init__(self, location: str):
self.s = {}
@ -8,6 +11,7 @@ class BuypeebSettings:
self.s['favouriteUpdateInterval'] = 5 * 60
self.s['updateIntervalCritical'] = 60
self.s['favouriteUpdateIntervalCritical'] = 30
self.s['watchlist'] = []
self.location = location
def save(self):
@ -18,7 +22,7 @@ class BuypeebSettings:
os.makedirs(self.location, 0o755)
open(self.location + "config.json", 'x')
try:
self.s = json.load(open(self.location + "config.json", 'r'))
self.s.update(json.load(open(self.location + "config.json", 'r')))
except:
print("Couldn't load settings - using defaults")
@ -27,3 +31,6 @@ class BuypeebSettings:
def set(self, setting: str, value):
self.s['setting'] = value
def watch(self, name: string, url: string):
self.s['watchlist'].add(YahooAuctionsItem(name, url))