prevent duplicate items from being watched
This commit is contained in:
parent
1d9a704f68
commit
42eecc28cc
4 changed files with 38 additions and 27 deletions
13
buypeeb.py
13
buypeeb.py
|
@ -75,7 +75,7 @@ class BuypeebApp:
|
|||
flags = 0,
|
||||
message_type = form,
|
||||
buttons = Gtk.ButtonsType.OK,
|
||||
message_format = title
|
||||
text = title
|
||||
)
|
||||
|
||||
msgbox.format_secondary_text(text)
|
||||
|
@ -119,15 +119,18 @@ class BuypeebApp:
|
|||
def renderList(self):
|
||||
self.items.clear()
|
||||
print(self.settings.watchlist)
|
||||
for item in self.settings.watchlist:
|
||||
for id, item in self.settings.watchlist.items():
|
||||
print("heeh hoo")
|
||||
self.items.append([item.name, item.price_aud(self.rate), "heenlo", item.id])
|
||||
self.items.append([item.name, item.price_aud(self.rate), "heenlo", id])
|
||||
|
||||
def btnAddClicked(self, widget):
|
||||
url = self.entryBox("Add URL", "Enter the URL of the item you want to add.")
|
||||
if url:
|
||||
if functions.rmatch("", url):
|
||||
# vry simpl url validation for simpol creachers
|
||||
if functions.rmatch("https?.+yahoo.+", url):
|
||||
self.settings.watch(url)
|
||||
else:
|
||||
self.msgBox("Invalid URL", "The provided URL was invalid.", Gtk.MessageType.ERROR)
|
||||
|
||||
self.renderList()
|
||||
|
||||
|
@ -137,7 +140,7 @@ class BuypeebApp:
|
|||
flags = 0,
|
||||
message_type = Gtk.MessageType.QUESTION,
|
||||
buttons = Gtk.ButtonsType.OK_CANCEL,
|
||||
message_format = "Really quit?"
|
||||
text = "Really quit?"
|
||||
)
|
||||
|
||||
prompt.format_secondary_text("Are you sure you want to quit buypeeb?")
|
||||
|
|
10
functions.py
10
functions.py
|
@ -12,5 +12,15 @@ def get_exchange_rate():
|
|||
except:
|
||||
return 76.15
|
||||
|
||||
def id_from_url(url: str):
|
||||
try:
|
||||
url = re.match(r"([^?]+)", url.rstrip("/")).group(1) # remove trailing slashes and query params
|
||||
except:
|
||||
# ???
|
||||
raise
|
||||
id = re.match(r".+\/(.+?)$", url).group(1) # extract "x12345" from "https://buyee.jp/whatever/blah/x12345"
|
||||
|
||||
return id
|
||||
|
||||
def rmatch(pattern, string):
|
||||
return re.match(pattern, string) != None
|
||||
|
|
18
listing.py
18
listing.py
|
@ -8,24 +8,22 @@ import functions
|
|||
JST = timezone(timedelta(hours = 9))
|
||||
|
||||
class YahooAuctionsItem:
|
||||
def __init__(self, url: str, name: str = None, from_json: dict = None):
|
||||
def __init__(self, url: str, id: str, name: str = None, from_json: dict = None):
|
||||
# note - incoming url is not validated in any way!
|
||||
self.name = name
|
||||
if url == None and from_json != None:
|
||||
self.id = from_json['id']
|
||||
if url == None and from_json != None and id != None:
|
||||
self.id = id
|
||||
self.name = from_json['name']
|
||||
self.original_name = from_json['original_name']
|
||||
self.favourite = from_json['favourite']
|
||||
self.url = f"https://buyee.jp/item/yahoo/auction/{self.id}"
|
||||
|
||||
else:
|
||||
try:
|
||||
self.url = re.match(r"([^?]+)", url.rstrip("/")).group(1) # remove trailing slashes and query params
|
||||
except:
|
||||
# ???
|
||||
raise
|
||||
self.id = re.match(r".+\/(.+?)$", self.url).group(1) # extract "x12345" from "https://buyee.jp/whatever/blah/x12345"
|
||||
elif url != None and id != None:
|
||||
self.url = url
|
||||
self.id = id
|
||||
|
||||
else:
|
||||
raise RuntimeError
|
||||
|
||||
self.last_checked = datetime.fromisoformat('1970-01-01')
|
||||
self.available = True
|
||||
|
|
24
settings.py
24
settings.py
|
@ -10,20 +10,19 @@ class BuypeebSettings:
|
|||
self.favouriteUpdateInterval = 5 * 60
|
||||
self.updateIntervalCritical = 60
|
||||
self.favouriteUpdateIntervalCritical = 30
|
||||
self.watchlist = []
|
||||
self.jwatchlist = []
|
||||
self.watchlist = {}
|
||||
self.jwatchlist = {}
|
||||
self.location = location
|
||||
|
||||
def save(self):
|
||||
for item in self.watchlist:
|
||||
self.jwatchlist.append({
|
||||
"id": item.id,
|
||||
for id, item in self.watchlist.items():
|
||||
self.jwatchlist[id] = {
|
||||
"name": item.name,
|
||||
"original_name": item.original_name,
|
||||
"favourite": False
|
||||
})
|
||||
}
|
||||
|
||||
self.watchlist = []
|
||||
self.watchlist = {}
|
||||
|
||||
print(self.__dict__)
|
||||
json.dump(self.__dict__, open(self.location + "config.json", 'w'))
|
||||
|
@ -37,16 +36,17 @@ class BuypeebSettings:
|
|||
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))
|
||||
for key in self.jwatchlist:
|
||||
self.watchlist[key] = YahooAuctionsItem(None, from_json = self.jwatchlist[key], id = key)
|
||||
|
||||
self.jwatchlist = []
|
||||
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:
|
||||
id = functions.id_from_url(url)
|
||||
self.watchlist[id] = YahooAuctionsItem(url, id, name)
|
||||
for item in self.watchlist.values():
|
||||
print(item.name, item.price)
|
||||
|
|
Loading…
Reference in a new issue