def calculate(): url = 'http://www.google.com/' timeout = 2 try: _ = requests.get(url, timeout=timeout) symbol = (request.form['ticketSymbol']) try: data = YahooFinancials(symbol) date = datetime.datetime.now(tzlocal()) timezone = str(time.asctime(time.localtime(time.time()))) strftime = date.strftime("%Z") financials = data.get_stock_quote_type_data() name = str(financials.get(symbol).get('longName')) sym = financials.get(symbol).get('symbol') current = str(data.get_current_price()) currentchange = str(round(data.get_current_change(), 2)) percentchange = str( round(data.get_current_percent_change() * 100, 2)) + '%' return render_template('output.html', symbol=symbol, data=data, timezone=timezone, strftime=strftime, financials=financials, name=name, sym=sym, current=current, currentchange=currentchange, percentchange=percentchange) except: return 'INVALID SYMBOL' except: return 'NO INTERNET CONNECTION'
def update_graph_interactive_image(value): value, label, stock = int(value.split("$$$$$")[1]), value.split( "$$$$$")[0], value.split("$$$$$")[2] if value == 0: yahoo_financials = YahooFinancials(stock) input = yahoo_financials.get_financial_stmts('annual', 'income') htmls = json2html.convert( json=input, table_attributes="id=\"info-table\" class=\"table-inverse\"") uc = dash_dangerously_set_inner_html.DangerouslySetInnerHTML( str(htmls)) elif value == 1: yahoo_financials = YahooFinancials(stock) input = yahoo_financials.get_financial_stmts('annual', 'balance') htmls = json2html.convert( json=input, table_attributes="id=\"info-table\" class=\"table-inverse\"") uc = dash_dangerously_set_inner_html.DangerouslySetInnerHTML( str(htmls)) elif value == 2: yahoo_financials = YahooFinancials(stock) input = yahoo_financials.get_financial_stmts('quarterly', 'cash') htmls = json2html.convert( json=input, table_attributes="id=\"info-table\" class=\"table-inverse\"") uc = dash_dangerously_set_inner_html.DangerouslySetInnerHTML( str(htmls)) elif value == 3: yahoo_financials = YahooFinancials(stock) input = yahoo_financials.get_stock_quote_type_data() htmls = json2html.convert( json=input, table_attributes="id=\"info-table\" class=\"table-inverse\"") uc = dash_dangerously_set_inner_html.DangerouslySetInnerHTML( str(htmls)) print(uc) return [ html.Div([ html.Div(html.H5(label + " Report of " + stock), style={"padding": "2%"}), html.Div([uc], style={ "overflow-x": "auto", "overflow-y": "auto", "height": "750px" }) ]) ]
def get(self, ticker: str) -> asset_returns: try: ticker = ticker.upper() yf = YahooFinancials(ticker) quote_type_data = yf.get_stock_quote_type_data() # This one seems very slow key_stats = yf.get_key_statistics_data() return json.dumps({ 'ticker': ticker, 'quote_type_data': quote_type_data[ticker], 'key_stats': key_stats[ticker] }) except Exception as e: return {'message': 'Unable to retrive prices'}, 500
def defaultapi(ticker): tick = YF(ticker) print(tick.get_stock_summary_data()) print(mark) print(tick.get_stock_quote_type_data()) print(mark) print(tick.get_stock_price_data()) print(mark) print(tick.get_current_price()) print(mark) print(tick.get_dividend_rate()) try: r = tick._cache.keys() except AttributeError: pass else: print(mark) print(r)
def get_fundamentals(symbol): check_existence() yahoo_financials = YahooFinancials(symbol) stock_type = yahoo_financials.get_stock_quote_type_data() annual_stmt = yahoo_financials.get_financial_stmts('annual', ['balance', 'income', 'cash']) return stock_type, annual_stmt