diff --git a/listing.py b/listing.py index 8f9b750..e7b8ed2 100644 --- a/listing.py +++ b/listing.py @@ -1,6 +1,6 @@ import requests -import re, json +import re, json, math from datetime import datetime, timezone, timedelta import functions @@ -116,6 +116,8 @@ class YahooAuctionsItem: if self.name == None or self.name == "": self.name = j['productName'] + self.available = (self.end_date_local() >= datetime.now(LOCALTIME)) + self.ready = True self.updating = False @@ -145,7 +147,24 @@ class YahooAuctionsItem: return self.start_date.astimezone(LOCALTIME) def ending_in(self, local = False): - return "heenlo" + if local: + difference = self.end_date_local() - datetime.now(tz = LOCALTIME) + else: + difference = self.end_date - datetime.now(tz = JST) + + ds = int(difference.total_seconds()) + + seconds = ds % 60 + minutes = math.floor(ds / 60) % 60 + hours = math.floor(ds / (60 * 60)) % 24 + days = math.floor(ds / (60 * 60 * 24)) + + out = "" + if days > 0: out += f"{days}d " + if hours > 0: out += f"{hours}h " + if minutes > 0: out += f"{minutes}m " + + return f"{out}{seconds}s" def ending_at(self, local = False): now = datetime.now(tz = LOCALTIME)