From 9bf9b3f83441ef5b8263d5ebd90c88b0f7cf70b7 Mon Sep 17 00:00:00 2001 From: vikyw89 Date: Mon, 29 Jan 2024 15:46:09 +0800 Subject: [PATCH] fix: get news --- finviz/main_func.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/finviz/main_func.py b/finviz/main_func.py index a39596e..5e99747 100644 --- a/finviz/main_func.py +++ b/finviz/main_func.py @@ -107,10 +107,13 @@ def get_news(ticker): results = [] date = None for row in rows: - raw_timestamp = row.xpath("./td")[0].xpath("text()")[0][0:-2] + raw_timestamp = str(row.xpath("./td")[0].xpath("text()")[0][0:-2]).strip() if len(raw_timestamp) > 8: - parsed_timestamp = datetime.strptime(raw_timestamp, "%b-%d-%y %I:%M%p") + if 'Today' in raw_timestamp: + parsed_timestamp = datetime.now() + else: + parsed_timestamp = datetime.strptime(raw_timestamp, "%b-%d-%y %I:%M%p") date = parsed_timestamp.date() else: parsed_timestamp = datetime.strptime(raw_timestamp, "%I:%M%p").replace(