Compare commits

..

No commits in common. "b83f45d15e4ab6e54bd9ed5fa45aff7035033341" and "6c5a93b0d8229503403b4a7aca0bd934af5bf657" have entirely different histories.

2 changed files with 23 additions and 52 deletions

View file

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

View file

@ -106,8 +106,6 @@ class YahooAuctionsItem:
self.ready = True
self.updating = False
return self.id, [self.name, self.price_aud(), self.ending_at()]
def price_jpy(self):
return f"¥{self.price:.0f}"
@ -116,13 +114,3 @@ class YahooAuctionsItem:
def ending_in(self):
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}"