Show market status and timestamp

Closes: #1
This commit is contained in:
Edward Betts 2023-10-07 23:44:12 +01:00
parent a163f68d59
commit c1ce0db188

View file

@ -49,6 +49,8 @@ class Index:
price: decimal.Decimal price: decimal.Decimal
subtitle: str subtitle: str
title: str title: str
state: str
timestamp: str
def __init__(self, name: str): def __init__(self, name: str):
"""Init.""" """Init."""
@ -104,6 +106,11 @@ class Index:
percent_change_str = tag[1][0].text_content().strip() percent_change_str = tag[1][0].text_content().strip()
percent_change_str = percent_change_str.replace("\N{MINUS SIGN}", "-") percent_change_str = percent_change_str.replace("\N{MINUS SIGN}", "-")
assert tag[2][0][0].text and tag[2][0][1].text
self.state = tag[2][0][0].text.rstrip(": ").lower()
self.timestamp = tag[2][0][1].text
self.day_change = decimal.Decimal(percent_change_str) self.day_change = decimal.Decimal(percent_change_str)
m = re_percent_change.match(tag[1][1].text_content()) m = re_percent_change.match(tag[1][1].text_content())
assert m assert m
@ -115,4 +122,7 @@ class Index:
@property @property
def one_line(self) -> str: def one_line(self) -> str:
"""Index name, price and price change.""" """Index name, price and price change."""
return f"{self.title}: {self.price} ({self.percent_change}%)" return (
f"{self.title}: {self.price} ({self.percent_change}%) "
+ f"{self.state} {self.timestamp}"
)