mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +00:00
refactor to allow to access articles from latest/trending commands
This commit is contained in:
@@ -48,7 +48,6 @@ class DiscoveryController:
|
||||
"spectrum",
|
||||
"latest",
|
||||
"trending",
|
||||
"news_article",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
@@ -92,7 +91,6 @@ class DiscoveryController:
|
||||
print(" spectrum spectrum of sectors, industry, country [Finviz]")
|
||||
print(" latest latest news [SeekingAlpha]")
|
||||
print(" trending trending news [SeekingAlpha]")
|
||||
print(" news_article news article [SeekingAlpha]")
|
||||
print("")
|
||||
|
||||
def switch(self, an_input: str):
|
||||
@@ -201,10 +199,6 @@ class DiscoveryController:
|
||||
"""Process trending command"""
|
||||
seeking_alpha_view.trending_news_view(other_args)
|
||||
|
||||
def call_news_article(self, other_args: List[str]):
|
||||
"""Process news_article command"""
|
||||
seeking_alpha_view.news_article_view(other_args)
|
||||
|
||||
|
||||
def menu():
|
||||
"""Discovery Menu"""
|
||||
|
||||
@@ -73,15 +73,22 @@ def latest_news_view(other_args: List[str]):
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
argparse other args - ["-n", "5"]
|
||||
argparse other args - ["-i", "123123", "-n", "5"]
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="latest",
|
||||
description="""Latest news articles. [Source: Seeking Alpha]""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--id",
|
||||
action="store",
|
||||
dest="n_id",
|
||||
type=check_positive,
|
||||
default=-1,
|
||||
help="article number found on Seeking Alpha website",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--num",
|
||||
@@ -92,24 +99,44 @@ def latest_news_view(other_args: List[str]):
|
||||
help="number of latest articles being printed",
|
||||
)
|
||||
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
other_args.insert(0, "-i")
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
articles = seeking_alpha_model.get_article_list(ns_parser.n_num)
|
||||
for idx, article in enumerate(articles):
|
||||
# User wants to see all latest news
|
||||
if ns_parser.n_id == -1:
|
||||
articles = seeking_alpha_model.get_article_list(ns_parser.n_num)
|
||||
for idx, article in enumerate(articles):
|
||||
print(
|
||||
article["publishedAt"].replace("T", " ").replace("Z", ""),
|
||||
"-",
|
||||
article["id"],
|
||||
"-",
|
||||
article["title"],
|
||||
)
|
||||
print(article["url"])
|
||||
print("")
|
||||
|
||||
if idx >= ns_parser.n_num - 1:
|
||||
break
|
||||
|
||||
# User wants to access specific article
|
||||
else:
|
||||
article = seeking_alpha_model.get_article_data(ns_parser.n_id)
|
||||
print(
|
||||
article["publishedAt"].replace("T", " ").replace("Z", ""),
|
||||
"-",
|
||||
article["id"],
|
||||
"-",
|
||||
article["publishedAt"][: article["publishedAt"].rfind(":") - 3].replace(
|
||||
"T", " "
|
||||
),
|
||||
" ",
|
||||
article["title"],
|
||||
)
|
||||
print(article["url"])
|
||||
print("")
|
||||
|
||||
if idx >= ns_parser.n_num - 1:
|
||||
break
|
||||
print(article["content"])
|
||||
|
||||
|
||||
def trending_news_view(other_args: List[str]):
|
||||
@@ -118,15 +145,22 @@ def trending_news_view(other_args: List[str]):
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
argparse other args - ["-n", "5"]
|
||||
argparse other args - ["i", "123123", "-n", "5"]
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="trending",
|
||||
description="""Trending news articles. [Source: Seeking Alpha]""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--id",
|
||||
action="store",
|
||||
dest="n_id",
|
||||
type=check_positive,
|
||||
default=-1,
|
||||
help="article number found on Seeking Alpha website",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--num",
|
||||
@@ -137,59 +171,41 @@ def trending_news_view(other_args: List[str]):
|
||||
help="number of trending articles being printed",
|
||||
)
|
||||
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
other_args.insert(0, "-i")
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
articles = seeking_alpha_model.get_trending_list(ns_parser.n_num)
|
||||
for idx, article in enumerate(articles):
|
||||
# User wants to see all trending articles
|
||||
if ns_parser.n_id == -1:
|
||||
articles = seeking_alpha_model.get_trending_list(ns_parser.n_num)
|
||||
for idx, article in enumerate(articles):
|
||||
print(
|
||||
article["publishedAt"].replace("T", " ").replace("Z", ""),
|
||||
"-",
|
||||
article["id"],
|
||||
"-",
|
||||
article["title"],
|
||||
)
|
||||
print(article["url"])
|
||||
print("")
|
||||
|
||||
if idx >= ns_parser.n_num - 1:
|
||||
break
|
||||
|
||||
# User wants to access specific article
|
||||
else:
|
||||
article = seeking_alpha_model.get_article_data(ns_parser.n_id)
|
||||
print(
|
||||
article["publishedAt"].replace("T", " ").replace("Z", ""),
|
||||
"-",
|
||||
article["id"],
|
||||
"-",
|
||||
article["publishedAt"][: article["publishedAt"].rfind(":") - 3].replace(
|
||||
"T", " "
|
||||
),
|
||||
" ",
|
||||
article["title"],
|
||||
)
|
||||
print(article["url"])
|
||||
print("")
|
||||
|
||||
if idx >= ns_parser.n_num - 1:
|
||||
break
|
||||
|
||||
|
||||
def news_article_view(other_args: List[str]):
|
||||
"""Prints a news article
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
argparse other args - ["-i", "3681944"]
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="up_article",
|
||||
description="""News article. [Source: Seeking Alpha]""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--id",
|
||||
action="store",
|
||||
dest="n_id",
|
||||
type=check_positive,
|
||||
default=-1,
|
||||
help="article number found on Seeking Alpha website",
|
||||
)
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
if ns_parser.n_id == -1:
|
||||
return
|
||||
|
||||
article = seeking_alpha_model.get_article_data(ns_parser.n_id)
|
||||
print(article["publishedAt"], " ", article["title"])
|
||||
print(article["url"])
|
||||
print("")
|
||||
print(article["content"])
|
||||
print(article["content"])
|
||||
|
||||
Reference in New Issue
Block a user