Add commands to open website of company, and another to open their HQ location (#583)

* fa/info improvement

* Open company's website from fundamental analysis

* Open company's HQ location

* check that hq location fields exist
This commit is contained in:
DidierRLopes
2021-08-01 00:23:46 +01:00
committed by GitHub
parent a6c0614d89
commit 4e264977f3
2 changed files with 91 additions and 1 deletions

View File

@@ -44,6 +44,8 @@ class FundamentalAnalysisController:
"shrs",
"sust",
"cal",
"web",
"hq",
"overview",
"key",
"income",
@@ -107,6 +109,8 @@ class FundamentalAnalysisController:
print(" shrs shareholders of the company")
print(" sust sustainability values of the company")
print(" cal calendar earnings and estimates of the company")
print(" web open web browser of the company")
print(" hq open HQ location of the company")
print("")
print("Alpha Vantage API:")
print(" overview overview of the company")
@@ -200,6 +204,14 @@ class FundamentalAnalysisController:
"""Process cal command"""
yahoo_finance_view.calendar_earnings(other_args, self.ticker)
def call_web(self, other_args: List[str]):
"""Process web command"""
yahoo_finance_view.web(other_args, self.ticker)
def call_hq(self, other_args: List[str]):
"""Process hq command"""
yahoo_finance_view.headquarters(other_args, self.ticker)
def call_overview(self, other_args: List[str]):
"""Process overview command"""
av_view.overview(other_args, self.ticker)

View File

@@ -4,6 +4,7 @@ __docformat__ = "numpy"
import argparse
from typing import List
from datetime import datetime
import webbrowser
import yfinance as yf
import pandas as pd
@@ -14,6 +15,81 @@ from gamestonk_terminal.helper_funcs import (
)
def headquarters(other_args: List[str], ticker: str):
"""Headquarters location of the company
Parameters
----------
other_args : List[str]
argparse other args
ticker : str
Fundamental analysis ticker symbol
"""
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="hq",
description="""
Opens in Google Maps HQ location of the company. [Source: Yahoo Finance]
""",
)
try:
ns_parser = parse_known_args_and_warn(parser, other_args)
if not ns_parser:
return
stock = yf.Ticker(ticker)
df_info = pd.DataFrame(stock.info.items(), columns=["Metric", "Value"])
df_info = df_info.set_index("Metric")
maps = "https://www.google.com/maps/search/"
for field in ["address1", "address2", "city", "state", "zip", "country"]:
if field in df_info.index:
maps += (
df_info[df_info.index == field]["Value"].values[0].replace(" ", "+")
+ ","
)
webbrowser.open(maps[:-1])
print("")
except Exception as e:
print(e, "\n")
def web(other_args: List[str], ticker: str):
"""Website of the company
Parameters
----------
other_args : List[str]
argparse other args
ticker : str
Fundamental analysis ticker symbol
"""
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="web",
description="""
Opens company's website. [Source: Yahoo Finance]
""",
)
try:
ns_parser = parse_known_args_and_warn(parser, other_args)
if not ns_parser:
return
stock = yf.Ticker(ticker)
df_info = pd.DataFrame(stock.info.items(), columns=["Metric", "Value"])
webbrowser.open(df_info[df_info["Metric"] == "website"]["Value"].values[0])
print("")
except Exception as e:
print(e, "\n")
def info(other_args: List[str], ticker: str):
"""Yahoo Finance ticker info
@@ -70,7 +146,9 @@ def info(other_args: List[str], ticker: str):
).strftime("%d/%m/%Y")
df_info = df_info.mask(df_info["Value"].astype(str).eq("[]")).dropna()
df_info = df_info.applymap(lambda x: long_number_format(x))
df_info[df_info.index != "Zip"] = df_info[df_info.index != "Zip"].applymap(
lambda x: long_number_format(x)
)
df_info = df_info.rename(
index={