From aeb015568eb98b33d7de6816a5b7745c288960c7 Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 28 Aug 2020 18:16:52 +1000 Subject: [PATCH] display auction end times in local timezone --- buypeeb.py | 6 +++--- listing.py | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/buypeeb.py b/buypeeb.py index a6bd8a0..62917b1 100755 --- a/buypeeb.py +++ b/buypeeb.py @@ -198,7 +198,7 @@ class BuypeebApp: self.items.set(treeIter, 0, item.name if item.name is not None else "") if item.ready: - listing[1], listing[2], listing[3] = item.price_jpy(), item.price_aud(), item.ending_at() + listing[1], listing[2], listing[3] = item.price_jpy(), item.price_aud(), item.ending_at(True) else: listing[0] = "Loading..." if item.name == "" else item.name for i in range(1, 4): @@ -208,7 +208,7 @@ class BuypeebApp: def updateListTimes(self): for listing in self.items: item = self.settings.watchlist[listing[4]] - listing[3] = item.ending_at() + listing[3] = item.ending_at(True) def updateSidePane(self, id: str): item = self.settings.watchlist[id] @@ -218,7 +218,7 @@ class BuypeebApp: "YahooName": item.original_name, "Price": item.price_jpy(), "PriceAUD": item.price_aud(), - "Ending": item.ending_in(), + "Ending": item.ending_in(True), "Bids": str(item.bids), "BuyItNow": f"{item.price_jpy(win = True)} ({item.price_aud(win = True)})" if item.win_price not in [0, "0", None, ""] else "No", "AutoExtension": "Yes" if item.auto_extension else "No", diff --git a/listing.py b/listing.py index aa5663c..8f9b750 100644 --- a/listing.py +++ b/listing.py @@ -6,6 +6,7 @@ from datetime import datetime, timezone, timedelta import functions JST = timezone(timedelta(hours = 9)) +LOCALTIME = timezone(timedelta(hours = 10)) # TODO: allow for customisation class YahooAuctionsItem: """ @@ -60,7 +61,8 @@ class YahooAuctionsItem: self.win_price = 0 self.original_name = "" self.favourite = None - self.end_date = None + self.end_date = datetime.fromisoformat('1970-01-01').replace(tzinfo = JST) + self.start_date = datetime.fromisoformat('1970-01-01').replace(tzinfo = JST) self.bids = 0 self.auto_extension = None self.rate = 75.0 @@ -136,14 +138,21 @@ class YahooAuctionsItem: p = self.win_price return f"${self.price / rate:.2f}" - def ending_in(self): + def end_date_local(self): + return self.end_date.astimezone(LOCALTIME) + + def start_date_local(self): + return self.start_date.astimezone(LOCALTIME) + + def ending_in(self, local = False): return "heenlo" - def ending_at(self): - now = datetime.now() + def ending_at(self, local = False): + now = datetime.now(tz = LOCALTIME) ndate = now.strftime("%d %b") if self.end_date != None: - idate, itime = self.end_date.strftime("%d %b"), self.end_date.strftime("%H:%M") + ed = self.end_date_local() if local else self.end_date + idate, itime = ed.strftime("%d %b"), ed.strftime("%H:%M") if idate == ndate: return itime else: