print the time remaining, i don't think it's perfect yet though

This commit is contained in:
Lynne Megido 2020-08-28 18:53:08 +10:00
parent aeb015568e
commit fabf38c736
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90

View File

@ -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)