multithreading is too frickin hard

This commit is contained in:
Lynne Megido 2020-08-24 00:47:40 +10:00
parent 72b05e7f37
commit b8e2ed8c86
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 22 additions and 20 deletions

View file

@ -45,7 +45,8 @@ else:
def watchlist_update_done(future): def watchlist_update_done(future):
try: try:
print(future.result()) print(future.result())
app.updateListItem(future.result()[0], future.result()[1]) app.settings.watchlist[future.result()[0]] = future.result()[1]
app.updateListItem(future.result()[0])
# app.renderList() # app.renderList()
except: except:
raise raise
@ -183,25 +184,22 @@ class BuypeebApp:
self.updateListTimes() self.updateListTimes()
def updateListItem(self, id: str, item_list = None): def updateListItem(self, id: str):
item = self.settings.watchlist[id] item = self.settings.watchlist[id]
for listing in self.items: for listing in self.items:
if listing[4] == id: if listing[4] == id:
# print(f"Updating {id} ({item.name}, {item.price_aud()}, {item.ready})") # print(f"Updating {id} ({item.name}, {item.price_aud()}, {item.ready})")
treeIter = Gtk.TreeModel.get_iter(self.items, listing.path) treeIter = Gtk.TreeModel.get_iter(self.items, listing.path)
if item_list != None:
for i in range(0, 4): self.items.set(treeIter, 0, item.name if item.name is not None else "")
self.items.set(treeIter, i, item_list[i] if item_list[0] is not None else "") if item.ready:
self.items.set(treeIter, 1, item.price_jpy())
self.items.set(treeIter, 2, item.price_aud())
self.items.set(treeIter, 3, item.ending_at())
else: else:
self.items.set(treeIter, 0, item.name if item.name is not None else "") self.items.set(treeIter, 1, "...")
if item.ready: self.items.set(treeIter, 2, "...")
self.items.set(treeIter, 1, item.price_jpy()) self.items.set(treeIter, 3, "...")
self.items.set(treeIter, 2, item.price_aud())
self.items.set(treeIter, 3, item.ending_at())
else:
self.items.set(treeIter, 1, "...")
self.items.set(treeIter, 2, "...")
self.items.set(treeIter, 3, "...")
def updateListTimes(self): def updateListTimes(self):
@ -211,6 +209,7 @@ class BuypeebApp:
def updateSidePane(self, id: str): def updateSidePane(self, id: str):
item = self.settings.watchlist[id] item = self.settings.watchlist[id]
print(item.__dict__)
info = { info = {
"Name": item.name, "Name": item.name,
"YahooName": item.original_name, "YahooName": item.original_name,
@ -302,6 +301,7 @@ class BuypeebApp:
def tveItemsSelectionChanged(self, selection): def tveItemsSelectionChanged(self, selection):
items, treeIter = selection.get_selected() items, treeIter = selection.get_selected()
print(items, treeIter)
if treeIter == None: if treeIter == None:
return return
row = items[treeIter] row = items[treeIter]

View file

@ -53,11 +53,11 @@ class YahooAuctionsItem:
end_date : datetime end_date : datetime
The end date and time of the item in JST. The end date and time of the item in JST.
""" """
def __init__(self, url: str, id: str, name: str = None, from_json: dict = None): def __init__(self, url: str, id: str, name: str = "", from_json: dict = None):
# note - incoming url is not validated in any way! # note - incoming url is not validated in any way!
self.name = name self.name = name
self.price = 0 self.price = 0
self.original_name = None self.original_name = ""
self.favourite = None self.favourite = None
self.end_date = None self.end_date = None
self.bids = 0 self.bids = 0
@ -65,6 +65,8 @@ class YahooAuctionsItem:
if url == None and from_json != None and id != None: if url == None and from_json != None and id != None:
self.id = id self.id = id
self.name = from_json['name'] self.name = from_json['name']
if self.name == "":
self.name = self.original_name
self.original_name = from_json['original_name'] self.original_name = from_json['original_name']
self.favourite = from_json['favourite'] self.favourite = from_json['favourite']
self.url = f"https://buyee.jp/item/yahoo/auction/{self.id}" self.url = f"https://buyee.jp/item/yahoo/auction/{self.id}"
@ -100,13 +102,13 @@ class YahooAuctionsItem:
self.end_date = datetime.fromisoformat(j['endtime']).replace(tzinfo = JST) self.end_date = datetime.fromisoformat(j['endtime']).replace(tzinfo = JST)
self.last_checked = datetime.now(JST) self.last_checked = datetime.now(JST)
self.original_name = j['productName'] self.original_name = j['productName']
if self.name == None: if self.name == None or self.name == "":
self.name = j['productName'] self.name = j['productName']
self.ready = True self.ready = True
self.updating = False self.updating = False
return self.id, [self.name, self.price_jpy(), self.price_aud(), self.ending_at()] return self.id, self
def price_jpy(self): def price_jpy(self):
return f"¥{self.price:.0f}" return f"¥{self.price:.0f}"

View file

@ -38,7 +38,7 @@ class BuypeebSettings:
for key in j: for key in j:
setattr(self, key, j[key]) setattr(self, key, j[key])
for key in self.jwatchlist: for key in self.jwatchlist:
self.watchlist[key] = YahooAuctionsItem(None, from_json = self.jwatchlist[key], id = key) self.watchlist[key] = YahooAuctionsItem("", from_json = self.jwatchlist[key], id = key)
self.jwatchlist = {} self.jwatchlist = {}
@ -46,7 +46,7 @@ class BuypeebSettings:
raise raise
print("Couldn't load settings - using defaults") print("Couldn't load settings - using defaults")
def watch(self, url: str, name: str = None): def watch(self, url: str, name: str = ""):
id = functions.id_from_url(url) id = functions.id_from_url(url)
self.watchlist[id] = YahooAuctionsItem(url, id, name) self.watchlist[id] = YahooAuctionsItem(url, id, name)
for item in self.watchlist.values(): for item in self.watchlist.values():