multithreading is too frickin hard
This commit is contained in:
parent
72b05e7f37
commit
b8e2ed8c86
3 changed files with 22 additions and 20 deletions
28
buypeeb.py
28
buypeeb.py
|
@ -45,7 +45,8 @@ else:
|
|||
def watchlist_update_done(future):
|
||||
try:
|
||||
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()
|
||||
except:
|
||||
raise
|
||||
|
@ -183,25 +184,22 @@ class BuypeebApp:
|
|||
|
||||
self.updateListTimes()
|
||||
|
||||
def updateListItem(self, id: str, item_list = None):
|
||||
def updateListItem(self, id: str):
|
||||
item = self.settings.watchlist[id]
|
||||
for listing in self.items:
|
||||
if listing[4] == id:
|
||||
# print(f"Updating {id} ({item.name}, {item.price_aud()}, {item.ready})")
|
||||
treeIter = Gtk.TreeModel.get_iter(self.items, listing.path)
|
||||
if item_list != None:
|
||||
for i in range(0, 4):
|
||||
self.items.set(treeIter, i, item_list[i] if item_list[0] is not None else "")
|
||||
|
||||
self.items.set(treeIter, 0, item.name if item.name 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:
|
||||
self.items.set(treeIter, 0, item.name if item.name 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:
|
||||
self.items.set(treeIter, 1, "...")
|
||||
self.items.set(treeIter, 2, "...")
|
||||
self.items.set(treeIter, 3, "...")
|
||||
self.items.set(treeIter, 1, "...")
|
||||
self.items.set(treeIter, 2, "...")
|
||||
self.items.set(treeIter, 3, "...")
|
||||
|
||||
|
||||
def updateListTimes(self):
|
||||
|
@ -211,6 +209,7 @@ class BuypeebApp:
|
|||
|
||||
def updateSidePane(self, id: str):
|
||||
item = self.settings.watchlist[id]
|
||||
print(item.__dict__)
|
||||
info = {
|
||||
"Name": item.name,
|
||||
"YahooName": item.original_name,
|
||||
|
@ -302,6 +301,7 @@ class BuypeebApp:
|
|||
|
||||
def tveItemsSelectionChanged(self, selection):
|
||||
items, treeIter = selection.get_selected()
|
||||
print(items, treeIter)
|
||||
if treeIter == None:
|
||||
return
|
||||
row = items[treeIter]
|
||||
|
|
10
listing.py
10
listing.py
|
@ -53,11 +53,11 @@ class YahooAuctionsItem:
|
|||
end_date : datetime
|
||||
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!
|
||||
self.name = name
|
||||
self.price = 0
|
||||
self.original_name = None
|
||||
self.original_name = ""
|
||||
self.favourite = None
|
||||
self.end_date = None
|
||||
self.bids = 0
|
||||
|
@ -65,6 +65,8 @@ class YahooAuctionsItem:
|
|||
if url == None and from_json != None and id != None:
|
||||
self.id = id
|
||||
self.name = from_json['name']
|
||||
if self.name == "":
|
||||
self.name = self.original_name
|
||||
self.original_name = from_json['original_name']
|
||||
self.favourite = from_json['favourite']
|
||||
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.last_checked = datetime.now(JST)
|
||||
self.original_name = j['productName']
|
||||
if self.name == None:
|
||||
if self.name == None or self.name == "":
|
||||
self.name = j['productName']
|
||||
|
||||
self.ready = True
|
||||
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):
|
||||
return f"¥{self.price:.0f}"
|
||||
|
|
|
@ -38,7 +38,7 @@ class BuypeebSettings:
|
|||
for key in j:
|
||||
setattr(self, key, j[key])
|
||||
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 = {}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class BuypeebSettings:
|
|||
raise
|
||||
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)
|
||||
self.watchlist[id] = YahooAuctionsItem(url, id, name)
|
||||
for item in self.watchlist.values():
|
||||
|
|
Loading…
Reference in a new issue