From 17416405332b6eef9b4328833b27cba9ede6ea9b Mon Sep 17 00:00:00 2001 From: didier Date: Fri, 16 Apr 2021 22:42:36 +0100 Subject: [PATCH 1/8] Improve datetime shown in trending/latest disc news --- gamestonk_terminal/discovery/seeking_alpha_model.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/discovery/seeking_alpha_model.py b/gamestonk_terminal/discovery/seeking_alpha_model.py index 7e85ca8ea70..a4857827a0a 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,15 @@ 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" + ) + .time() + .strftime("%Y-%m-%d %H:%M:%S"), "url": "https://seekingalpha.com" + article_url, "id": article_id, } @@ -166,7 +172,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, } From 1bba88b2e671ebd21bd74fd5a080e3b9879cc18d Mon Sep 17 00:00:00 2001 From: didier Date: Fri, 16 Apr 2021 23:10:50 +0100 Subject: [PATCH 2/8] refactor to allow to access articles from latest/trending commands --- .../discovery/disc_controller.py | 6 - .../discovery/seeking_alpha_view.py | 140 ++++++++++-------- 2 files changed, 78 insertions(+), 68 deletions(-) diff --git a/gamestonk_terminal/discovery/disc_controller.py b/gamestonk_terminal/discovery/disc_controller.py index a9a66116107..d74eaf19814 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): @@ -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""" 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"]) From d3b17532f0be873e013d2c8f5cd9915512263e1c Mon Sep 17 00:00:00 2001 From: didier Date: Fri, 16 Apr 2021 23:14:57 +0100 Subject: [PATCH 3/8] minor typo --- gamestonk_terminal/discovery/seeking_alpha_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gamestonk_terminal/discovery/seeking_alpha_model.py b/gamestonk_terminal/discovery/seeking_alpha_model.py index a4857827a0a..3f056b22a2e 100755 --- a/gamestonk_terminal/discovery/seeking_alpha_model.py +++ b/gamestonk_terminal/discovery/seeking_alpha_model.py @@ -129,7 +129,6 @@ def get_article_list(num: int) -> List[dict]: "publishedAt": datetime.strptime( item_row["data-last-date"], "%Y-%m-%d %H:%M:%S %z" ) - .time() .strftime("%Y-%m-%d %H:%M:%S"), "url": "https://seekingalpha.com" + article_url, "id": article_id, From 1c8994abe9a48fc08ef2513ecb8fd2c979235e69 Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Fri, 16 Apr 2021 23:22:56 +0100 Subject: [PATCH 4/8] Update README.md --- gamestonk_terminal/discovery/README.md | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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. ![cntry_spec](https://user-images.githubusercontent.com/25267873/113639067-48fd5e80-9670-11eb-95cf-0931845ddd12.png) + + +## 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. + +latest + + +## 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. + +trending + From bd906bcb2375538080c04540074687e1daea6681 Mon Sep 17 00:00:00 2001 From: didier Date: Fri, 16 Apr 2021 23:27:26 +0100 Subject: [PATCH 5/8] spacing --- gamestonk_terminal/discovery/disc_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/discovery/disc_controller.py b/gamestonk_terminal/discovery/disc_controller.py index d74eaf19814..ac0ac589526 100644 --- a/gamestonk_terminal/discovery/disc_controller.py +++ b/gamestonk_terminal/discovery/disc_controller.py @@ -89,8 +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(" latest latest news [Seeking Alpha]") + print(" trending trending news [Seeking Alpha]") print("") def switch(self, an_input: str): From 96b15688759675fbd11b75c79529757c4fab2602 Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Fri, 16 Apr 2021 23:28:56 +0100 Subject: [PATCH 6/8] Update README.md --- gamestonk_terminal/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 +  From ce6c369968d0208c719b3b143acf495cde391164 Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Fri, 16 Apr 2021 23:31:42 +0100 Subject: [PATCH 7/8] Update ROADMAP.md --- ROADMAP.md | 1 + 1 file changed, 1 insertion(+) 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** From 27aa3251b03279b37464ebee1ba7c2258e853b40 Mon Sep 17 00:00:00 2001 From: didier Date: Fri, 16 Apr 2021 23:32:07 +0100 Subject: [PATCH 8/8] make lint happy --- gamestonk_terminal/discovery/seeking_alpha_model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gamestonk_terminal/discovery/seeking_alpha_model.py b/gamestonk_terminal/discovery/seeking_alpha_model.py index 3f056b22a2e..b573c506d3f 100755 --- a/gamestonk_terminal/discovery/seeking_alpha_model.py +++ b/gamestonk_terminal/discovery/seeking_alpha_model.py @@ -128,8 +128,7 @@ def get_article_list(num: int) -> List[dict]: "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"), + ).strftime("%Y-%m-%d %H:%M:%S"), "url": "https://seekingalpha.com" + article_url, "id": article_id, }