mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-11 20:01:16 +00:00
introduce start date to fetch the (latest) news from
This commit is contained in:
@@ -91,12 +91,14 @@ def get_articles_html(url_articles: str) -> str:
|
||||
return articles_html
|
||||
|
||||
|
||||
def get_article_list(num: int) -> List[dict]:
|
||||
def get_article_list(start_date: datetime, num: int) -> List[dict]:
|
||||
"""Returns a list of latest articles
|
||||
|
||||
Parameters
|
||||
----------
|
||||
pages : int
|
||||
start_date : datetime
|
||||
Starting date
|
||||
num : int
|
||||
Number of articles
|
||||
|
||||
Returns
|
||||
@@ -122,13 +124,15 @@ def get_article_list(num: int) -> List[dict]:
|
||||
if not article_url.startswith("/news/"):
|
||||
continue
|
||||
article_id = article_url.split("/")[2].split("-")[0]
|
||||
|
||||
article_date = datetime.strptime(
|
||||
item_row["data-last-date"], "%Y-%m-%d %H:%M:%S %z"
|
||||
)
|
||||
if start_date.date() < article_date.date():
|
||||
continue
|
||||
articles.append(
|
||||
{
|
||||
"title": item.text,
|
||||
"publishedAt": datetime.strptime(
|
||||
item_row["data-last-date"], "%Y-%m-%d %H:%M:%S %z"
|
||||
).strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"publishedAt": article_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"url": "https://seekingalpha.com" + article_url,
|
||||
"id": article_id,
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ __docformat__ = "numpy"
|
||||
import argparse
|
||||
from typing import List
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
check_positive,
|
||||
parse_known_args_and_warn,
|
||||
valid_date,
|
||||
)
|
||||
|
||||
from gamestonk_terminal.discovery import seeking_alpha_model
|
||||
@@ -98,6 +100,15 @@ def latest_news_view(other_args: List[str]):
|
||||
default=10,
|
||||
help="number of latest articles being printed",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--date",
|
||||
action="store",
|
||||
dest="n_date",
|
||||
type=valid_date,
|
||||
default=datetime.now().strftime("%Y-%m-%d"),
|
||||
help="starting date of latest articles being printed",
|
||||
)
|
||||
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
@@ -109,7 +120,9 @@ def latest_news_view(other_args: List[str]):
|
||||
|
||||
# User wants to see all latest news
|
||||
if ns_parser.n_id == -1:
|
||||
articles = seeking_alpha_model.get_article_list(ns_parser.n_num)
|
||||
articles = seeking_alpha_model.get_article_list(
|
||||
ns_parser.n_date, ns_parser.n_num
|
||||
)
|
||||
for idx, article in enumerate(articles):
|
||||
print(
|
||||
article["publishedAt"].replace("T", " ").replace("Z", ""),
|
||||
|
||||
Reference in New Issue
Block a user