add trending news list, from Seeking Alpha

This commit is contained in:
Hinko Kocevar
2021-04-16 10:44:48 +02:00
parent 1ceb938610
commit f2bc9c1cbe
3 changed files with 88 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ class DiscoveryController:
"performance",
"spectrum",
"latest",
"trending",
"news_article"
]
@@ -90,6 +91,7 @@ class DiscoveryController:
print(" performance performance of sectors, industry, country [Finviz]")
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("")
@@ -195,6 +197,10 @@ class DiscoveryController:
"""Process latest command"""
seeking_alpha_view.latest_news_view(other_args)
def call_trending(self, other_args: List[str]):
"""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)

View File

@@ -133,6 +133,43 @@ def get_article_list(num: int) -> list:
return articles
def get_trending_list(num: int) -> list:
"""Returns a list of trending articles
Parameters
----------
pages : int
Number of articles
Returns
-------
list
Trending articles list
"""
articles = list()
url_articles = "https://seekingalpha.com/news/trending_news"
response = requests.get(url_articles, headers={"User-Agent": get_user_agent()})
# Check that the API response was successful
if response.status_code != 200:
print("Invalid response\n")
else:
for item in response.json():
article_url = item['uri']
if not article_url.startswith('/news/'):
continue
article_id = article_url.split('/')[2].split('-')[0]
articles.append({
'title': item['title'],
'publishedAt': item['publish_on'],
'url': "https://seekingalpha.com"+article_url,
'id': article_id
})
return articles
def get_article_data(article_id: int) -> dict:
"""Returns an article

View File

@@ -112,6 +112,51 @@ def latest_news_view(other_args: List[str]):
break
def trending_news_view(other_args: List[str]):
"""Prints the trending news article list
Parameters
----------
other_args : List[str]
argparse other args - ["-n", "5"]
"""
parser = argparse.ArgumentParser(
add_help=False,
prog="trending",
description="""Trending news articles. [Source: Seeking Alpha]""",
)
parser.add_argument(
"-n",
"--num",
action="store",
dest="n_num",
type=check_positive,
default=10,
help="number of trending articles being printed.",
)
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):
print(
article["publishedAt"].replace("T", " ").replace("Z", ""),
"-",
article['id'],
"-",
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