From c1ce0db188dbdb19bbbb63bd52fcecf6c2abd8fa Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 7 Oct 2023 23:44:12 +0100 Subject: [PATCH] Show market status and timestamp Closes: #1 --- google_stocks/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/google_stocks/__init__.py b/google_stocks/__init__.py index 57a3122..31b4cba 100644 --- a/google_stocks/__init__.py +++ b/google_stocks/__init__.py @@ -49,6 +49,8 @@ class Index: price: decimal.Decimal subtitle: str title: str + state: str + timestamp: str def __init__(self, name: str): """Init.""" @@ -104,6 +106,11 @@ class Index: percent_change_str = tag[1][0].text_content().strip() 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) m = re_percent_change.match(tag[1][1].text_content()) assert m @@ -115,4 +122,7 @@ class Index: @property def one_line(self) -> str: """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}" + )