Files
OpenBB/gamestonk_terminal/cryptocurrency/overview/cryptopanic_view.py
Colin Delahunty 571e5281e3 Improved crypto handling (#1279)
* Improved crypto handling

* Fixed some tests

* Fixed some tests

* Fixed flake8

* Updated to fix tests

Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
2022-02-01 11:56:51 -05:00

74 lines
2.1 KiB
Python

"""Cryptopanic view"""
__docformat__ = "numpy"
import logging
import os
from typing import Optional
from gamestonk_terminal.cryptocurrency.overview import cryptopanic_model
from gamestonk_terminal.decorators import log_start_end
from gamestonk_terminal.helper_funcs import export_data, print_rich_table
from gamestonk_terminal.rich_config import console
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def display_news(
post_kind: str = "news",
region: str = "en",
filter_: Optional[str] = None,
top: int = 25,
sortby: str = "published_at",
descend: bool = False,
links: bool = False,
export: str = "",
) -> None:
"""Display recent posts from CryptoPanic news aggregator platform. [Source: https://cryptopanic.com/]
Parameters
----------
top: int
number of news to display
post_kind: str
Filter by category of news. Available values: news or media.
filter_: Optional[str]
Filter by kind of news. One from list: rising|hot|bullish|bearish|important|saved|lol
region: str
Filter news by regions. Available regions are: en (English), de (Deutsch), nl (Dutch), es (Español),
fr (Français), it (Italiano), pt (Português), ru (Русский)
sortby: str
Key to sort by.
descend: bool
Sort in descending order.
links: bool
Show urls for news
export : str
Export dataframe data to csv,json,xlsx file
"""
df = cryptopanic_model.get_news(
limit=top, post_kind=post_kind, filter_=filter_, region=region
)
if not df.empty:
df = df.sort_values(by=sortby, ascending=descend)
if not links:
df.drop("link", axis=1, inplace=True)
else:
df = df[["title", "link"]]
print_rich_table(
df.head(top),
headers=list(df.columns),
show_index=False,
title="Recent CryptoPanic Posts",
)
console.print("")
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"news",
df,
)