Compare commits
2 commits
6c5a93b0d8
...
b83f45d15e
Author | SHA1 | Date | |
---|---|---|---|
b83f45d15e | |||
1fd1fb21d0 |
2 changed files with 52 additions and 23 deletions
51
buypeeb.py
51
buypeeb.py
|
@ -33,6 +33,8 @@ import functions
|
|||
from listing import YahooAuctionsItem, JST
|
||||
from settings import BuypeebSettings
|
||||
|
||||
app = None
|
||||
|
||||
isWindows = sys.platform.startswith('win')
|
||||
|
||||
if isWindows:
|
||||
|
@ -40,6 +42,14 @@ 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)
|
||||
|
@ -47,18 +57,19 @@ class WatchlistUpdater(Thread):
|
|||
self.update_all = update_all
|
||||
|
||||
def run(self):
|
||||
# TODO: make this happen in parallel
|
||||
with ProcessPool(max_workers = 4) as pool:
|
||||
if self.update_all:
|
||||
for id, item in self.app.settings.watchlist.items():
|
||||
if not (item.ready or item.updating):
|
||||
item.update()
|
||||
future = pool.schedule(item.update)
|
||||
future.add_done_callback(watchlist_update_done)
|
||||
|
||||
else:
|
||||
for item in self.app.settings.outdated_items():
|
||||
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:
|
||||
|
||||
# SETUP
|
||||
|
@ -167,18 +178,25 @@ class BuypeebApp:
|
|||
|
||||
self.updateListTimes()
|
||||
|
||||
def updateListTimes(self):
|
||||
now = datetime.now()
|
||||
ndate = now.strftime("%d %b")
|
||||
for listing in self.items:
|
||||
id = listing[3]
|
||||
def updateListItem(self, id: str, item_list = None):
|
||||
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
|
||||
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:
|
||||
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):
|
||||
item = self.settings.watchlist[id]
|
||||
|
@ -188,7 +206,7 @@ class BuypeebApp:
|
|||
"Price": item.price_jpy(),
|
||||
"PriceAUD": item.price_aud(),
|
||||
"Ending": item.ending_in(),
|
||||
"Bids": item.bids
|
||||
"Bids": str(item.bids)
|
||||
}
|
||||
|
||||
for label, contents in info.items():
|
||||
|
@ -200,7 +218,6 @@ class BuypeebApp:
|
|||
|
||||
self.builder.get_object("lblSelectedName").set_label("buypeeb")
|
||||
|
||||
|
||||
# BUTTON CLICKS
|
||||
|
||||
def btnAddClicked(self, widget):
|
||||
|
@ -251,7 +268,7 @@ class BuypeebApp:
|
|||
if name:
|
||||
item.name = name
|
||||
|
||||
self.renderList() # TODO: only update the changed item
|
||||
self.updateListItem(item.id)
|
||||
|
||||
def btnSelectedRemoveClicked(self, widget):
|
||||
del self.settings.watchlist[self.selected]
|
||||
|
|
12
listing.py
12
listing.py
|
@ -106,6 +106,8 @@ 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}"
|
||||
|
||||
|
@ -114,3 +116,13 @@ 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}"
|
||||
|
|
Loading…
Reference in a new issue