update in parallel
This commit is contained in:
parent
1fd1fb21d0
commit
b83f45d15e
2 changed files with 32 additions and 15 deletions
45
buypeeb.py
45
buypeeb.py
|
@ -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,14 +178,19 @@ class BuypeebApp:
|
||||||
|
|
||||||
self.updateListTimes()
|
self.updateListTimes()
|
||||||
|
|
||||||
def updateListItem(self, id: str):
|
def updateListItem(self, id: str, item_list = None):
|
||||||
item = self.settings.watchlist[id]
|
item = self.settings.watchlist[id]
|
||||||
for listing in self.items:
|
for listing in self.items:
|
||||||
if listing[3] == id:
|
if listing[3] == id:
|
||||||
|
# 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)
|
||||||
self.items.set(treeIter, 0, item.name)
|
if item_list != None:
|
||||||
self.items.set(treeIter, 1, item.price_aud())
|
for i in range(0, 3):
|
||||||
self.items.set(treeIter, 2, item.ending_at())
|
self.items.set(treeIter, i, item_list[i])
|
||||||
|
else:
|
||||||
|
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):
|
def updateListTimes(self):
|
||||||
|
@ -202,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):
|
||||||
|
|
|
@ -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}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue