def add_stock_holdings(): user = get_or_create(session, User, email='*****@*****.**')[0] portfolio = get_or_create(session, Portfolio, user=user, name='My First Portfolio')[0] df = pd.read_csv('data/activity_until_20160222.csv', index_col=0, parse_dates=True, usecols=range(8)) currency_column_to_number(df, 'Price') for row in df.iterrows(): data = row[1] stock = get_or_create(session, Stock, symbol=data['Symbol'])[0] get_or_create(session, StockHolding, shares=data['Quantity'], price=data['Price'], date=data['Date'], portfolio=portfolio, stock=stock )
def add_users(): get_or_create(session, User, email='*****@*****.**', password='******') get_or_create(session, User, email='*****@*****.**', password='******', display_name='Zach4', first_name='ZachIV', last_name='Liu') user3 = get_or_create(session, User, email='*****@*****.**', password='******')[0] user3.display_name = 'Zach3'
def add_stock_holdings(): user = get_or_create(session, User, email='*****@*****.**')[0] portfolio = get_or_create(session, Portfolio, user=user, name='My First Portfolio')[0] df = pd.read_csv('data/activity_until_20160222.csv', index_col=0, parse_dates=True, usecols=range(8)) currency_column_to_number(df, 'Price') for row in df.iterrows(): data = row[1] stock = get_or_create(session, Stock, symbol=data['Symbol'])[0] get_or_create(session, StockHolding, shares=data['Quantity'], price=data['Price'], date=data['Date'], portfolio=portfolio, stock=stock)
def add_portfolios(): user = get_or_create(session, User, email='*****@*****.**')[0] get_or_create(session, Portfolio, user=user, name='My First Portfolio') get_or_create(session, Portfolio, user=user, name='My Second Portfolio') user2 = get_or_create(session, User, email='*****@*****.**')[0] get_or_create(session, Portfolio, user=user2, name='Zach2 First Portfolio') get_or_create(session, Portfolio, user=user2, name='Zach2 Second Portfolio') get_or_create(session, Portfolio, user=user2, name='Zach2 Third Portfolio')
def add_stocks(): with open('data/list.txt', 'r') as f: for symbol in f: get_or_create(session, Stock, symbol=symbol)
def test_add_user(self): user = get_or_create(session, User, email='*****@*****.**', password='******') print(user) user = get_or_create(session, User, email='*****@*****.**', password='******') print(user)
def query_demo(): user = get_or_create(session, User, email="*****@*****.**")[0] portfolio = session.query(Portfolio).filter(Portfolio.name == 'My First Portfolio', Portfolio.user == user) print() print(portfolio[0])