Compare commits

...

2 Commits

Author SHA1 Message Date
Lynne Megido b83f45d15e
update in parallel 2020-08-23 23:28:48 +10:00
Lynne Megido 1fd1fb21d0
don't redraw the whole list after a rename 2020-08-23 22:59:56 +10:00
2 changed files with 52 additions and 23 deletions

View File

@ -33,6 +33,8 @@ import functions
from listing import YahooAuctionsItem, JST from listing import YahooAuctionsItem, JST
from settings import BuypeebSettings from settings import BuypeebSettings
app = None
isWindows = sys.platform.startswith('win') isWindows = sys.platform.startswith('win')
if isWindows: if isWindows:
@ -40,6 +42,14 @@ if isWindows:
else: else:
settingsLocation = path.expanduser("~/.config/Lynnear Software/buypeeb/") # dotfiles in ~ need to die. begone dot settingsLocation = path.expanduser("~/.config/Lynnear Software/buypeeb/") # dotfiles in ~ need to die. begone dot
def watchlist_update_done(future):
try:
print(future.result())
app.updateListItem(future.result()[0], future.result()[1])
# app.renderList()
except:
raise
class WatchlistUpdater(Thread): class WatchlistUpdater(Thread):
def __init__(self, app, update_all: bool = False): def __init__(self, app, update_all: bool = False):
Thread.__init__(self) Thread.__init__(self)
@ -47,18 +57,19 @@ class WatchlistUpdater(Thread):
self.update_all = update_all self.update_all = update_all
def run(self): def run(self):
# TODO: make this happen in parallel with ProcessPool(max_workers = 4) as pool:
if self.update_all: if self.update_all:
for id, item in self.app.settings.watchlist.items(): for id, item in self.app.settings.watchlist.items():
if not (item.ready or item.updating): if not (item.ready or item.updating):
item.update() future = pool.schedule(item.update)
future.add_done_callback(watchlist_update_done)
else: else:
for item in self.app.settings.outdated_items(): for item in self.app.settings.outdated_items():
if not(item.ready or item.updating): if not(item.ready or item.updating):
item.update() future = pool.schedule(item.update)
future.add_done_callback(watchlist_update_done)
self.app.renderList()
class BuypeebApp: class BuypeebApp:
# SETUP # SETUP
@ -167,18 +178,25 @@ class BuypeebApp:
self.updateListTimes() self.updateListTimes()
def updateListTimes(self): def updateListItem(self, id: str, item_list = None):
now = datetime.now() item = self.settings.watchlist[id]
ndate = now.strftime("%d %b")
for listing in self.items: for listing in self.items:
id = listing[3] if listing[3] == id:
item = self.settings.watchlist[id] # print(f"Updating {id} ({item.name}, {item.price_aud()}, {item.ready})")
if item.end_date != None: treeIter = Gtk.TreeModel.get_iter(self.items, listing.path)
idate, itime = item.end_date.strftime("%d %b"), item.end_date.strftime("%H:%M") if item_list != None:
if idate == ndate: for i in range(0, 3):
listing[2] = itime self.items.set(treeIter, i, item_list[i])
else: else:
listing[2] = f"{idate} {itime}" self.items.set(treeIter, 0, item.name)
self.items.set(treeIter, 1, item.price_aud())
self.items.set(treeIter, 2, item.ending_at())
def updateListTimes(self):
for listing in self.items:
item = self.settings.watchlist[listing[3]]
listing[2] = item.ending_at()
def updateSidePane(self, id: str): def updateSidePane(self, id: str):
item = self.settings.watchlist[id] item = self.settings.watchlist[id]
@ -188,7 +206,7 @@ class BuypeebApp:
"Price": item.price_jpy(), "Price": item.price_jpy(),
"PriceAUD": item.price_aud(), "PriceAUD": item.price_aud(),
"Ending": item.ending_in(), "Ending": item.ending_in(),
"Bids": item.bids "Bids": str(item.bids)
} }
for label, contents in info.items(): for label, contents in info.items():
@ -200,7 +218,6 @@ class BuypeebApp:
self.builder.get_object("lblSelectedName").set_label("buypeeb") self.builder.get_object("lblSelectedName").set_label("buypeeb")
# BUTTON CLICKS # BUTTON CLICKS
def btnAddClicked(self, widget): def btnAddClicked(self, widget):
@ -251,7 +268,7 @@ class BuypeebApp:
if name: if name:
item.name = name item.name = name
self.renderList() # TODO: only update the changed item self.updateListItem(item.id)
def btnSelectedRemoveClicked(self, widget): def btnSelectedRemoveClicked(self, widget):
del self.settings.watchlist[self.selected] del self.settings.watchlist[self.selected]

View File

@ -106,6 +106,8 @@ class YahooAuctionsItem:
self.ready = True self.ready = True
self.updating = False self.updating = False
return self.id, [self.name, self.price_aud(), self.ending_at()]
def price_jpy(self): def price_jpy(self):
return f"¥{self.price:.0f}" return f"¥{self.price:.0f}"
@ -114,3 +116,13 @@ class YahooAuctionsItem:
def ending_in(self): def ending_in(self):
return "heenlo" return "heenlo"
def ending_at(self):
now = datetime.now()
ndate = now.strftime("%d %b")
if self.end_date != None:
idate, itime = self.end_date.strftime("%d %b"), self.end_date.strftime("%H:%M")
if idate == ndate:
return itime
else:
return f"{idate} {itime}"