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)