def testapi(): """Test to see if API is working""" conn = Connection(app_site()) print 'Attempting to get data from API...' conn.get('data_source') print 'Content retreived via API!'
def worth_data(): conn = Connection(app_site()) tables = [ 'transaction', 'dividend', 'security_prices', 'price', 'security_data'] table = request.args.get('table', 'USD') res = [getattr(conn, t) for t in tables] res.append(conn.commodity_ids(table)) # TODO: Fix 'nan' error with init_db mp = Worth(*res) worth = mp.convert_worth(mp.calc_worth()) return jsonify( result=worth, id=mp.currency_id, missing=mp.missing, empty=mp.empty)
def popprices(sym=None, start=None, end=None, extra=None): """Add prices (and optionally dividends or splits) to securities in the database """ with app.app_context(): conn = Historical(app_site()) keys = conn.get('keys') sym = sym.split(',') if sym else None values = conn.get_price_list(sym, start, end, extra) conn.post(conn.process(values, keys)) print 'Prices table populated'
def popdb(): """Remove all content from database, initializes it, and populates it with sample data """ initdb() conn = Historical(app_site()) date = d.today() - timedelta(days=30) keys = conn.get('keys') content = [conn.process(v, keys) for v in conn.get('pop_values')] [conn.post(values) for values in content] post_all(conn, keys) price = conn.get_first_price(conn.securities, date) conn.post(conn.process(price, keys)) print 'Database populated'
def initdb(): """Remove all content from database and initializes it with default values """ resetdb() conn = Historical(app_site()) date = d.today() - timedelta(days=45) keys = conn.get('keys') content = [conn.process(v, keys) for v in conn.get('init_values')] [conn.post(values) for values in content] post_all(conn, keys) price = conn.get_first_price(conn.securities, date) conn.post(conn.process(price, keys)) print 'Database initialized'
def resetdb(): """Remove all content from database and creates new tables""" conn = Connection(app_site()) conn.get('reset') print 'Database reset'
def get_vars(self, table): table_as_class = table.title().replace('_', '') conn = HelpForm(app_site()) form = init_form(eval('%sForm' % table_as_class)) return form, conn, redir
def transaction(): conn = HelpForm(app_site()) form = init_form(TransactionForm) kwargs = conn.get_kwargs(table, 'cronus', conn.get('keys'), form, False) return render_template('entry.html', **kwargs)
def help(): with app.app_context(): return HelpForm(app_site())
def get_vars(self, table): table_as_class = table.title().replace('_', '') form = init_form(eval('%sForm' % table_as_class)) conn = HelpForm(app_site()) redir = '.get' return form, conn, redir
def get(table): conn = HelpForm(app_site()) table_as_class = table.title().replace('_', '') form = init_form(eval('%sForm' % table_as_class)) kwargs = conn.get_kwargs(table, 'hermes', conn.get('keys'), form) return render_template('entry.html', **kwargs)