def financials(cik): """ View the financials """ if cik is None and 'ticker' in session and session['ticker'] != {}: return redirect(url_for('financials', cik=session['ticker']['cik'])) if cik is not None: store_cik(cik) if session['ticker'] == {}: flash('Invalid ticker', 'danger') return redirect('/financials/') if cik is None: return render_template('financials.jinja2', cik=None) if app.config['test_data'] == True: if cik != '1288776': return redirect('/financials/1288776/') params = {'ticker': cik, 'length': -5, 'frequency': 12} financials = ['sales', 'ebit', 'adj_ebit', 'ebitda', 'adj_ebitda', 'cfo_minus_capex'] margins = ['gross_profit_margin', 'adj_ebit_margin', 'adj_ebitda_margin', 'adj_pretax_income_margin', 'net_income_margin', 'dividend_yield'] ratios = ['net_debt_to_adj_ebitda', 'debt_to_assets', 'debt_to_equity', 'debt_to_interest_expense', 'return_on_invested_capital'] multiples = ['cev_to_sales', 'cev_to_adj_ebitda', 'price_to_earnings', 'price_to_tangible_book_value'] all_elements = financials + margins + ratios + multiples params['elements'] = ','.join(all_elements) response = make_api_request('/financials/detail/', params) dates = [] valid = [] # get rid of dates with length of 0 for i, date in enumerate(response['_results_']['_dates_']): if 'length' in date and date['length'] != 0: valid.append(i) dates.append(date) results = {'_labels_': response['_results_']['_labels_']} for key, values in response['_results_'].iteritems(): if key not in ['_dates_', '_labels_']: if '_total_' in values: results[key] = [x for i, x in enumerate(values['_total_']) if i in valid] html = generate_financials_template() financials = html.render(elements=financials, results=results) margins = html.render(elements=margins, results=results) ratios = html.render(elements=ratios, results=results) multiples = html.render(elements=multiples, results=results) return render_template('financials.jinja2', detail='true', dates=dates, financials=financials, margins=margins, ratios=ratios, multiples=multiples)
def filings(cik): """Filings list view""" if cik is None and 'ticker' in session and session['ticker'] != {}: cik = session['ticker']['cik'] if not request.is_xhr: return redirect('/filings/' + str(cik) + '/') if cik is not None: store_cik(cik) if session['ticker'] == {}: # if ticker is invalid flash('Invalid ticker', 'danger') return redirect('/filings/') params = {} try: page = int(request.args.get('page')) except: page = None if page != None: params['page'] = page try: params['forms'] = session['forms'] except: pass try: params['insiders'] = session['insiders'] except: pass try: params['ciks'] = session['ticker']['cik'] except: pass if 'watchlist_view' in session and session['watchlist_view'] == 'true': if 'watchlist_ciks' in session: params['ciks'] = ','.join([str(x) for x in session['watchlist_ciks']]) else: params['ciks'] = default_watchlist() response = make_api_request('/filings/list/', params) pagination = response.get('_pagination_', {'current': None, 'next': None}) html = generate_filings_template() html = html.render(filings=response['_results_']) if request.is_xhr: return jsonify(html=html, pagination=pagination) return render_template('filings.jinja2', html=html, results=response['_results_'], pagination=pagination)
def insiders(cik): """Get the latest insider filings. If cik is not None then get the latest insider filings for a specific company""" if cik is None and 'ticker' in session and session['ticker'] != {}: cik = session['ticker']['cik'] if not request.is_xhr: return redirect('/insiders/' + str(cik) + '/') if cik is not None: store_cik(cik) if session['ticker'] == {}: flash('Invalid ticker', 'danger') return redirect('/insiders/') params = {} if 'planned' in session: params['planned'] = session['planned'] try: params['ciks'] = session['ticker']['cik'] except: pass if 'watchlist_view' in session and session['watchlist_view'] == 'true': if 'watchlist_ciks' in session: params['ciks'] = ','.join([str(x) for x in session['watchlist_ciks']]) else: params['ciks'] = default_watchlist() try: page = int(request.args.get('page')) except: page = None if page != None: params['page'] = page response = make_api_request('/insiders/list/', params) pagination = response.get('_pagination_', {'current': None, 'next': None}) tmplate = generate_insider_template() html = tmplate.render(insiders=response['_results_'], session=session) if request.is_xhr: return jsonify(html=html, pagination=pagination) flash("Don't worry, we're gonna bring back the charts shortly", 'info') return render_template('insiders.jinja2', html=html, pagination=pagination)