mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
Merge pull request #2 from DidierRLopes/hinxn
Improve datetime shown in trending/latest disc news
This commit is contained in:
@@ -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**
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 <a name="map"></a>
|
||||
@@ -218,3 +222,30 @@ Spectrum of sectors, industry, country. [Source: Finviz]
|
||||
* -g : Data group (sector, industry or country). Default: Sector.
|
||||
|
||||

|
||||
|
||||
|
||||
## latest <a name="latest"></a>
|
||||
|
||||
```
|
||||
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.
|
||||
|
||||
<img width="1208" alt="latest" src="https://user-images.githubusercontent.com/25267873/115089633-926c6a00-9f0a-11eb-9d0e-1eedfd8ba7ce.png">
|
||||
|
||||
|
||||
## trending <a name="trending"></a>
|
||||
|
||||
```
|
||||
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.
|
||||
|
||||
<img width="1213" alt="trending" src="https://user-images.githubusercontent.com/25267873/115089640-96988780-9f0a-11eb-9ca7-70a245fa3960.png">
|
||||
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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