buypeeb/settings.py

52 lines
1.3 KiB
Python

import json, os, pickle
from os import path
import functions
from listing import YahooAuctionsItem
class BuypeebSettings:
def __init__(self, location: str):
self.updateInterval = 10 * 60
self.favouriteUpdateInterval = 5 * 60
self.updateIntervalCritical = 60
self.favouriteUpdateIntervalCritical = 30
self.watchlist = []
self.jwatchlist = []
self.location = location
def save(self):
for item in self.watchlist:
self.jwatchlist.append({
"id": item.id,
"name": item.name,
"original_name": item.original_name,
"favourite": False
})
self.watchlist = []
print(self.__dict__)
json.dump(self.__dict__, open(self.location + "config.json", 'w'))
def load(self):
if not path.isfile(self.location + "config.json"):
os.makedirs(self.location, 0o755, True)
open(self.location + "config.json", 'x')
else:
try:
j = json.load(open(self.location + "config.json", 'r'))
for key in j:
setattr(self, key, j[key])
for item in self.jwatchlist:
self.watchlist.append(YahooAuctionsItem(None, from_json = item))
self.jwatchlist = []
except:
raise
print("Couldn't load settings - using defaults")
def watch(self, url: str, name: str = None):
self.watchlist.append(YahooAuctionsItem(url, name))
for item in self.watchlist:
print(item.name, item.price)