From 77d3e868274838050ce6a160aa8c73cec17404d0 Mon Sep 17 00:00:00 2001 From: Lynne Date: Sun, 23 Aug 2020 22:17:33 +1000 Subject: [PATCH] now you can select items to view info about them --- buypeeb.py | 32 ++++++++++++++++++++++++++++++-- listing.py | 7 +++++-- requirements.txt | 1 + ui/main.glade | 13 ++++++------- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/buypeeb.py b/buypeeb.py index 879ef7c..3f26531 100755 --- a/buypeeb.py +++ b/buypeeb.py @@ -21,11 +21,13 @@ import requests, gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk +from pebble import ProcessPool import json, sys from os import path from threading import Thread from datetime import datetime +from concurrent.futures import TimeoutError import functions from listing import YahooAuctionsItem, JST @@ -151,12 +153,15 @@ class BuypeebApp: def renderList(self): self.items.clear() - print(self.settings.watchlist) + # print(self.settings.watchlist) for id, item in self.settings.watchlist.items(): if item.ready: self.items.append([item.name, item.price_aud(self.rate), "...", id]) else: - self.items.append([item.name, "...", "...", id]) + name = item.name + if name == None: + name = "Loading..." + self.items.append([name, "...", "...", id]) self.updateListTimes() @@ -173,6 +178,21 @@ class BuypeebApp: else: listing[2] = f"{idate} {itime}" + def updateSidePane(self, id: str): + item = self.settings.watchlist[id] + info = { + "Name": item.name, + "YahooName": item.original_name, + "Price": item.price_jpy(), + "PriceAUD": item.price_aud(), + "Ending": item.ending_in(), + "Bids": item.bids + } + + for label, contents in info.items(): + self.builder.get_object(f"lblSelected{label}").set_label(contents) + + # BUTTON CLICKS def btnAddClicked(self, widget): @@ -214,6 +234,14 @@ class BuypeebApp: if response: self.shutdown(self) + # OTHER UI INTERACTIONS + + def tveItemsSelectionChanged(self, selection): + items, treeIter = selection.get_selected() + row = items[treeIter] + id = row[3] + self.updateSidePane(id) + if __name__ == '__main__': app = BuypeebApp() app.run(sys.argv) diff --git a/listing.py b/listing.py index 0178cb0..184aba1 100644 --- a/listing.py +++ b/listing.py @@ -86,8 +86,8 @@ class YahooAuctionsItem: # the good news is, yahoo japan returns all the data we need in handy json format # the bad news is that the only way to get that json format is to download the whole auction page and grep it - r = requests.get(f"https://page.auctions.yahoo.co.jp/jp/auction/{self.id}").text - # r = open("yahoo.html").read() + # r = requests.get(f"https://page.auctions.yahoo.co.jp/jp/auction/{self.id}").text + r = open("yahoo.html").read() j = json.loads(re.match(r'.*var pageData ?= ?(\{.*?\});', r, re.DOTALL).group(1)) except: raise @@ -110,3 +110,6 @@ class YahooAuctionsItem: def price_aud(self, rate = 75.0): return f"${self.price / rate:.2f}" + + def ending_in(self): + return "heenlo" diff --git a/requirements.txt b/requirements.txt index 35aca7f..8804de5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ requests==2.24 PyGObject==3.36 +pebble==4.5 diff --git a/ui/main.glade b/ui/main.glade index d042ab3..1ddc7b9 100644 --- a/ui/main.glade +++ b/ui/main.glade @@ -275,7 +275,9 @@ 1 True - + + + @@ -343,10 +345,12 @@ True False - precious peebus polytonal player + buypeeb center True + end 40 + 3 @@ -442,7 +446,6 @@ True False end - something in japanese end @@ -455,7 +458,6 @@ True False end - ¥12345 2 @@ -467,7 +469,6 @@ True False end - $123.45 2 @@ -479,7 +480,6 @@ True False end - 1h 17m 23s 2 @@ -491,7 +491,6 @@ True False end - 5 2