diff --git a/ROADMAP.md b/ROADMAP.md
index f5c466f3a9a..df45ed9d191 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -33,6 +33,7 @@
* [x] Top Losers (@didier) - [PR #171](https://github.com/DidierRLopes/GamestonkTerminal/pull/171)
* [x] ARK orders (@aia) - [PR #140](https://github.com/DidierRLopes/GamestonkTerminal/pull/140)
* [x] Analyse sectors/industry performance, overview and valuation from Finviz (@didier) - [PR #315](https://github.com/DidierRLopes/GamestonkTerminal/pull/315)
+* [x] Add latest and trending news commands (@hinxx) - [PR #347](https://github.com/DidierRLopes/GamestonkTerminal/pull/347)
**NEXT**
diff --git a/gamestonk_terminal/README.md b/gamestonk_terminal/README.md
index 2b6d79c7b2e..09b25108e07 100644
--- a/gamestonk_terminal/README.md
+++ b/gamestonk_terminal/README.md
@@ -79,6 +79,8 @@ Command|Description|Source
`valuation` |valuation of sectors, industry, country |[Finviz](https://finviz.com)
`performance` |performance of sectors, industry, country |[Finviz](https://finviz.com)
`spectrum` |spectrum of sectors, industry, country |[Finviz](https://finviz.com)
+`latest` |latest news |[Seeking Alpha](https://seekingalpha.com/)
+`trending` |trending news |[Seeking Alpha](https://seekingalpha.com/)
@@ -351,4 +353,4 @@ technical |technical (e.g. Beta, SMA50, 52W Low, RSI, Change)
signals |view filter signals (e.g. -s top_gainers)
-
\ No newline at end of file
+
diff --git a/gamestonk_terminal/discovery/README.md b/gamestonk_terminal/discovery/README.md
index 517d142d334..2e69e69f056 100644
--- a/gamestonk_terminal/discovery/README.md
+++ b/gamestonk_terminal/discovery/README.md
@@ -32,6 +32,10 @@ This menu aims to discover new stocks, and the usage of the following commands a
* performance of sectors, industry, country [Finviz]
* [spectrum](#spectrum)
* spectrum of sectors, industry, country [Finviz]
+* [latest](#latest)
+ * latest news [Seeking Alpha]
+* [trending](#trending)
+ * trending news [Seeking Alpha]
## map
@@ -218,3 +222,30 @@ Spectrum of sectors, industry, country. [Source: Finviz]
* -g : Data group (sector, industry or country). Default: Sector.

+
+
+## latest
+
+```
+usage: latest [-i N_ID] [-n N_NUM]
+```
+
+Latest news articles. [Source: Seeking Alpha]
+* -i : article number found on Seeking Alpha website
+* -n : number of latest articles being printed. Default 10.
+
+
+
+
+## trending
+
+```
+usage: trending [-i N_ID] [-n N_NUM]
+```
+
+Trending news articles. [Source: Seeking Alpha]
+* -i : article number found on Seeking Alpha website
+* -n : number of trending articles being printed. Default 10.
+
+
+
diff --git a/gamestonk_terminal/discovery/disc_controller.py b/gamestonk_terminal/discovery/disc_controller.py
index a9a66116107..ac0ac589526 100644
--- a/gamestonk_terminal/discovery/disc_controller.py
+++ b/gamestonk_terminal/discovery/disc_controller.py
@@ -48,7 +48,6 @@ class DiscoveryController:
"spectrum",
"latest",
"trending",
- "news_article",
]
def __init__(self):
@@ -90,9 +89,8 @@ class DiscoveryController:
print(" valuation valuation of sectors, industry, country [Finviz]")
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(" latest latest news [Seeking Alpha]")
+ print(" trending trending news [Seeking Alpha]")
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"""
diff --git a/gamestonk_terminal/discovery/seeking_alpha_model.py b/gamestonk_terminal/discovery/seeking_alpha_model.py
index 7e85ca8ea70..b573c506d3f 100755
--- a/gamestonk_terminal/discovery/seeking_alpha_model.py
+++ b/gamestonk_terminal/discovery/seeking_alpha_model.py
@@ -6,6 +6,7 @@ import requests
from bs4 import BeautifulSoup
import pandas as pd
from pandas.core.frame import DataFrame
+from datetime import datetime
from gamestonk_terminal.helper_funcs import get_user_agent
@@ -121,10 +122,13 @@ def get_article_list(num: int) -> List[dict]:
if not article_url.startswith("/news/"):
continue
article_id = article_url.split("/")[2].split("-")[0]
+
articles.append(
{
"title": item.text,
- "publishedAt": item_row["data-last-date"],
+ "publishedAt": datetime.strptime(
+ item_row["data-last-date"], "%Y-%m-%d %H:%M:%S %z"
+ ).strftime("%Y-%m-%d %H:%M:%S"),
"url": "https://seekingalpha.com" + article_url,
"id": article_id,
}
@@ -166,7 +170,7 @@ def get_trending_list(num: int) -> list:
articles.append(
{
"title": item["title"],
- "publishedAt": item["publish_on"],
+ "publishedAt": item["publish_on"][: item["publish_on"].rfind(".")],
"url": "https://seekingalpha.com" + article_url,
"id": article_id,
}
diff --git a/gamestonk_terminal/discovery/seeking_alpha_view.py b/gamestonk_terminal/discovery/seeking_alpha_view.py
index 639e145f0d0..a11c548be72 100644
--- a/gamestonk_terminal/discovery/seeking_alpha_view.py
+++ b/gamestonk_terminal/discovery/seeking_alpha_view.py
@@ -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"])