diff options
author | jmaslek <jmaslek11@gmail.com> | 2021-09-03 19:26:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-03 19:26:02 -0400 |
commit | 7fbac7f68d9dad098634866bd1ded843fc2174e0 (patch) | |
tree | 9bb132b1520346f1e0d6ade54e144a8642237c1a | |
parent | ffcaa19e793351875592c6f0fb5a9f818efa713f (diff) |
Add realtime earnings from geekofwallstr (#731)
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | gamestonk_terminal/stocks/discovery/disc_controller.py | 48 | ||||
-rw-r--r-- | gamestonk_terminal/stocks/discovery/geekofwallstreet_model.py | 55 | ||||
-rw-r--r-- | gamestonk_terminal/stocks/discovery/geekofwallstreet_view.py | 56 | ||||
-rw-r--r-- | gamestonk_terminal/terminal_helper.py | 1 |
5 files changed, 154 insertions, 7 deletions
diff --git a/README.md b/README.md index 79ca751aa8d..afaf522ce12 100644 --- a/README.md +++ b/README.md @@ -400,6 +400,7 @@ Feel free to share loss porn, memes or any questions at: * **Chavithra** and **Deel18** : for Degiro's integration. * **Traceabl3** : By adding several preset screeners * **jpp** : Responsible by developing `Crypto` menu +* **rkornmeyer** : Provides realtime earnings data on https://thegeekofwallstreet.com/ <a href="https://github.com/GamestonkTerminal/GamestonkTerminal/graphs/contributors"> <img src="https://contributors-img.web.app/image?repo=GamestonkTerminal/GamestonkTerminal" height="276"/> diff --git a/gamestonk_terminal/stocks/discovery/disc_controller.py b/gamestonk_terminal/stocks/discovery/disc_controller.py index 07353516ccb..42b61531096 100644 --- a/gamestonk_terminal/stocks/discovery/disc_controller.py +++ b/gamestonk_terminal/stocks/discovery/disc_controller.py @@ -5,8 +5,10 @@ import argparse import os from typing import List from datetime import datetime + from matplotlib import pyplot as plt from prompt_toolkit.completion import NestedCompleter + from gamestonk_terminal import feature_flags as gtff from gamestonk_terminal.helper_funcs import get_flair from gamestonk_terminal.menu import session @@ -24,6 +26,7 @@ from gamestonk_terminal.stocks.discovery import ( shortinterest_view, yahoofinance_view, finnhub_view, + geekofwallstreet_view, ) @@ -56,6 +59,7 @@ class DiscoveryController: "trending", "lowfloat", "hotpenny", + "rtearn", ] CHOICES += CHOICES_COMMANDS @@ -74,10 +78,12 @@ class DiscoveryController: help_text = """https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/stocks/discovery Discovery: - cls clear screen") - ?/help show this menu again") - q quit this menu, and shows back to main menu") - quit quit to abandon program") + cls clear screen + ?/help show this menu again + q quit this menu, and shows back to main menu + quit quit to abandon program +Geek of Wall St: + rtearn realtime earnings from and expected moves Finnhub: pipo past IPOs dates fipo future IPOs dates @@ -146,6 +152,35 @@ pennystockflow.com """Process Quit command - quit the program""" return True + def call_rtearn(self, other_args: List[str]): + """Process rtearn command""" + parser = argparse.ArgumentParser( + add_help=False, + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + prog="rtearn", + description=""" + Realtime earnings data and expected moves. [Source: https://thegeekofwallstreet.com] + """, + ) + parser.add_argument( + "--export", + choices=["csv", "json", "xlsx"], + default="", + type=str, + dest="export", + help="Export dataframe data to csv,json,xlsx file", + ) + + try: + ns_parser = parse_known_args_and_warn(parser, other_args) + if not ns_parser: + return + + geekofwallstreet_view.display_realtime_earnings(ns_parser.export) + + except Exception as e: + print(e, "\n") + def call_pipo(self, other_args: List[str]): """Process pipo command""" parser = argparse.ArgumentParser( @@ -218,9 +253,8 @@ pennystockflow.com help="Export dataframe data to csv,json,xlsx file", ) try: - if other_args: - if "-" not in other_args[0]: - other_args.insert(0, "-n") + if other_args and "-" not in other_args[0]: + other_args.insert(0, "-n") ns_parser = parse_known_args_and_warn(parser, other_args) if not ns_parser: diff --git a/gamestonk_terminal/stocks/discovery/geekofwallstreet_model.py b/gamestonk_terminal/stocks/discovery/geekofwallstreet_model.py new file mode 100644 index 00000000000..1b62aa55384 --- /dev/null +++ b/gamestonk_terminal/stocks/discovery/geekofwallstreet_model.py @@ -0,0 +1,55 @@ +"""Geek of wall street model""" +__docformat__ = "numpy" + +import io +import requests +import pandas as pd + + +def download_file_from_google_drive(file_id: str) -> bytes: + """Custom function from rkornmeyer for pulling csv from google drive + + Parameters + ---------- + file_id : str + File id to pull from google drive + + Returns + ------- + bytes + Content from request response + """ + + def get_confirm_token(response): + for key, value in response.cookies.items(): + if key.startswith("download_warning"): + return value + + return None + + URL = "https://docs.google.com/uc?export=download" + + session = requests.Session() + + response = session.get(URL, params={"id": file_id}, stream=True) + token = get_confirm_token(response) + + if token: + params = {"id": file_id, "confirm": token} + response = session.get(URL, params=params, stream=True) + + return response.content + + +def get_realtime_earnings() -> pd.DataFrame: + """Pulls realtime earnings from geek of wallstreet + + Returns + ------- + pd.DataFrame + Dataframe containing realtime earnings + """ + data = download_file_from_google_drive("1-TsAuzKs_vvg40r5RuRaG_wyb2Hzxbd5").decode( + "utf-8" + ) + return pd.read_csv(io.StringIO(data)) diff --git a/gamestonk_terminal/stocks/discovery/geekofwallstreet_view.py b/gamestonk_terminal/stocks/discovery/geekofwallstreet_view.py new file mode 100644 index 00000000000..1873d6377de --- /dev/null +++ b/gamestonk_terminal/stocks/discovery/geekofwallstreet_view.py @@ -0,0 +1,56 @@ +"""Geek of wall street view""" +__docformat__ = "numpy" +import os + +import pandas as pd +from tabulate import tabulate + +import gamestonk_terminal.feature_flags as gtff +from gamestonk_terminal.helper_funcs import export_data +from gamestonk_terminal.stocks.discovery import geekofwallstreet_model as gwt_model + +# pylint:disable=no-member + + +def display_realtime_earnings(export: str = ""): + """Displays real time earnings data from geekofwallstreet.com + + Parameters + ---------- + export : str, optional + Format to export data + """ + earnings: pd.DataFrame = gwt_model.get_realtime_earnings() + earnings_export = earnings.copy() + # Make the table look pretty + earnings = earnings.drop( + columns=[ + "Name", + "Previous Earnings Date", + "Stock Type", + "Confirmation", + "Special Case", + "Conference Call", + "Press Release", + "Has Options", + ] + ).fillna("") + earnings["Market Cap"] = earnings["Market Cap"] / 1_000_000_000 + earnings = earnings.rename(columns={"Market Cap": "Market Cap ($1B)"}) + if gtff.USE_TABULATE_DF: + print( + tabulate( + earnings, + headers=earnings.columns, + tablefmt="fancy_grid", + showindex=False, + floatfmt=".3f", + ), + "\n", + ) + else: + print(earnings.to_string()) + + export_data( + export, os.path.dirname(os.path.abspath(__file__)), "rtearn", earnings_export + ) diff --git a/gamestonk_terminal/terminal_helper.py b/gamestonk_terminal/terminal_helper.py index 7f496644930..dfcb9b06c88 100644 --- a/gamestonk_terminal/terminal_helper.py +++ b/gamestonk_terminal/terminal_helper.py @@ -355,6 +355,7 @@ def about_us(): f"{Fore.CYAN}Quiver Quantitative: {Style.RESET_ALL}https://www.quiverquant.com\n" f"{Fore.CYAN}Ops.Syncretism: {Style.RESET_ALL}https://ops.syncretism.io/api.html\n" f"{Fore.CYAN}SentimentInvestor: {Style.RESET_ALL}https://sentimentinvestor.com\n" + f"{Fore.CYAN}The Geek of Wall Street: {Style.RESET_ALL}https://thegeekofwallstreet.com/\n" f"\n{Fore.RED}" "DISCLAIMER: Trading in financial instruments involves high risks including the risk of losing some, " "or all, of your investment amount, and may not be suitable for all investors. Before deciding to trade in " |