def portfolio_report(portfile: str, pricefile: str, fmt='txt'): portfolio = read_portfolio(portfile) prices = read_prices(pricefile) report = make_report(portfolio, prices) formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def main(list): 'print report given a portfolio csv file and prices csv file' portfolio = read_portfolio(list[1]) prices = read_prices(list[2]) report = make_report(portfolio, prices) formatter = tableformat.create_formatter(list[3]) print_report(report, formatter)
def ticker(fmt, fields): formatter = create_formatter(fmt) formatter.headings(fields) while True: rec = yield row = [getattr(rec, name) for name in fields] formatter.row(row)
def inventory_report(inventory, latest_prices, fmt='txt'): inv = read_inventory(inventory) price = read_prices(latest_prices) report = make_report(inv, price) formatter = create_formatter(fmt) print_report(report, formatter)
def portfolio_report(portfolio_filename: str, prices_filename: str, fmt: str = "txt"): portfolios = read_portfolio(portfolio_filename) prices = read_prices(prices_filename) report = make_report(portfolios, prices) formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(portfile, logfile, fmt): portfolio = read_portfolio(portfile) rows = parse_stock_data(follow(logfile)) rows = (row for row in rows if row['name'] in portfolio) formatter = tableformat.create_formatter(fmt) formatter.headings(['Name', 'Price', 'Change']) for row in rows: formatter.row([row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
def portfolio_report(portfolio_file, prices_file, fmt): ''' Creates a portfolio report from a portfolio file with current prices ''' portfolio = read_portfolio(f'{portfolio_file}') prices = read_prices(f'{prices_file}') report = make_report(portfolio, prices) formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(portfile, logfile, fmt): lines = follow(logfile) portfolio = read_portfolio(portfile) rows = parse_stock_data(lines) rows = filter_names(rows, portfolio) formatter = tableformat.create_formatter(fmt) formatter.headings(['Name', 'Price', 'Change']) for row in rows: formatter.row((row['Name'], str(row['Price']), str(row['Change'])))
def ticker(portfile, logfile, fmt): headers = ['name', 'price', 'change'] portfolio = report.read_portfolio(portfile) rows = parse_stock_data(follow(logfile), portfolio, headers) formatter = tableformat.create_formatter(fmt) formatter.headings(headers) for row in rows: formatter.row( [row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
def ticker(portfile,logfile,fmt): portfolio = report.read_portfolio(portfile) lines = follow(logfile) rows = parse_stock_data(lines) rows = filter_symbols(rows, portfolio) formatter = tableformat.create_formatter(fmt) formatter.headings(['Name','Price','Change']) for row in rows: formatter.row([ row['name'], f"{row['price']:0.2f}",f"{row['change']:0.2f}" ])
def portfolio_report(portfolio_filename, prices_filename, fmt='txt'): """ Creates the portfolio report """ portfolio = read_portfolio(portfolio_filename) prices = read_prices(prices_filename) report = make_report(portfolio, prices) formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(port, stream, fmt): port = read_portfolio(port) rows = parse_stock_data(follow(stream)) fmt = create_formatter(fmt) rows = filter_symbols(rows, port) fmt.headings(['Name', 'Price', 'Change']) for row in rows: fmt.row(tuple(row.values()))
def portfolio_report(portfolio_path: str, prices_path: str, fmt='txt'): portfolio = read_portfolio(portfolio_path) prices = read_prices(prices_path) #calculate_current_value(portfolio, prices) report = make_report(portfolio, prices) formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(portfolio, logfile, fmt): portfolio = report.read_portfolio_4(portfolio) lines = Follow(logfile) rows = parse_stock_data(lines) rows = filter_symbols(rows, portfolio) formatter = tableformat.create_formatter(fmt) formatter.headings(['name', 'price', 'shares']) for rowdata in rows: formatter.row(rowdata.values())
def portfolio_report(portfolio_filename, prices_filename, fmt='txt'): ''' Make a stock report given portfolio and price data files. ''' portfolio = read_portfolio(portfolio_filename) prices = read_prices(prices_filename) report = make_report(portfolio, prices) formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def portfolio_report(portfolio_filename, prices_filename, fmt='txt'): my_stocks = read_portfolio(portfolio_filename) current_price = read_prices(prices_filename) # Generation report data report = make_report(my_stocks, current_price) # output of the report formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(portfolio_path, logfile, fmt): portfolio = report.read_portfolio(portfolio_path) lines = follow(logfile) rows = parse_stock_data(lines) formatter = create_formatter(fmt) formatter.headings(['Name', 'Price', 'Change']) for row in rows: formatter.row(row)
def portfolio_report(portfolio_filename, prices_filename, fmt='txt'): # Read data files portfolio = read_portfolio(portfolio_filename) prices = read_prices(prices_filename) # Create the report data report = make_report(portfolio, prices) formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(portfile, logfile, fmt): import report portfolio = report.read_portfolio(portfile) rows = parse_stock_data(follow(logfile)) rows = (row for row in rows if row["name"] in portfolio) import tableformat formatter = tableformat.create_formatter(fmt) formatter.headings(["Name", "Price", "Change"]) for row in rows: formatter.row( [row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
def ticker(portfile, logfile, fmt): names = ['name', 'price', 'change'] portfolio = report.read_portfolio(portfile) rows = parse_stock_data(follow(logfile)) rows = select_columns(rows, [0, 1, 4]) rows = make_dicts(rows, names) rows = filter_symbols(rows, portfolio) formatter = create_formatter(fmt) formatter.headings([name.title() for name in names]) for row in rows: formatter.row([row['name'], row['price'], row['change']])
def ticker(portfile, logfile, fmt): portfolio = report.read_portfolio(portfile) lines = follow(logfile) rows = parse_stock_data(lines) rows = (row for row in rows if row['name'] in portfolio) # substitute filter_symbols() formatter = tableformat.create_formatter(fmt) formatter.headings('Name Price Change'.split()) for row in rows: formatter.row( [row['name'], f"{row['price']:0.2f}", f"{row['change']:0.2f}"])
def ticker(portfile, logfile, fmt): import report import tableformat portfolio = report.read_portfolio(portfile) rows = parse_stock_data(follow(logfile)) rows = filter_symbols(rows, portfolio) fmt = tableformat.create_formatter(fmt) fmt.headings(["Name", "Price", "Change"]) for row in rows: fmt.row([row["name"], str(row["price"]), str(row["change"])])
def portfolio_report(portfoliofile, pricesfile, fmt='txt'): # Read a data file portfolio = read_portfolio(portfoliofile) prices = read_prices(pricesfile) # Create a report data report = make_report(portfolio, prices) # Print it out formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(portfile, logfile, fmt): formatter = tableformat.create_formatter(fmt) formatter.headings(['Name', 'Price', 'Change']) portfolio = report.read_portfolio('Data/portfolio.csv') rows = parse_stock_data(follow('Data/stocklog.csv')) holdings = (row for row in rows if row['name'] in portfolio) for stock in holdings: formatter.row( [stock['name'], f"{stock['price']:0.2f}", f"{stock['change']:0.2f}"])
def ticker(portfolio_file, stocklog_file, fmt): portfolio = report.read_portfolio(portfolio_file) rows = parse_stock_data(follow(stocklog_file)) rows = (row for row in rows if row['name'] in portfolio) formatter = tableformat.create_formatter(fmt) formatter.headings(['Name', 'Price', 'Change']) for stock in rows: rowdata = [ stock['name'], f"{stock['price']:0.2f}", f"{stock['change']:0.2f}" ] formatter.row(rowdata)
def portfolio_report(portfoliofile, pricefile, fmt="txt"): """ Make a stock report given portfolio and price data files. """ # Read data files portfolio = read_portfolio(portfoliofile) prices = read_prices(pricefile) # Create the report data report = make_report(portfolio, prices) # Print it out formatter = create_formatter(fmt) print_report(report, formatter)
def portfolio_report( portfolio_filename="Data/portfolio.csv", prices_filename="Data/prices.csv", fmt="text", ): "print a report on your portfolio with current prices" portfolio = read_portfolio(portfolio_filename) with open(prices_filename) as prices: prices = dict(parse_csv(prices, has_headers=False, types=[str, float])) formatter = tableformat.create_formatter(fmt) print_report(portfolio, prices, formatter)
def ticker(filename, logfilename, fmt): inventory = read_inventory(filename) rows = parse_product_data(follow(logfilename)) # rows = filter_names(rows, inventory) rows = (row for row in rows if row['name'] in inventory) formatter = create_formatter(fmt) formatter.headings(['Name', 'prices', 'Change']) for row in rows: name = row['name'] price = row['price'] change = row['change'] rowdata = [name, f'{price:0.2f}', f'{change:0.2f}'] formatter.row(rowdata)
def portfolio_report(portfolio_filename, prices_filename, fmt='txt'): """Make a stock report given portfolio and price data files. """ # Read data files portfolio = read_portfolio(portfolio_filename) prices = read_prices(prices_filename) # Create the report data report = make_report(portfolio, prices) # Print it out formatter = tableformat.create_formatter(fmt) print_report(report, formatter)
def ticker(portfile, logfile, fmt): import report portfolio = report.read_portfolio(portfile) lines = follow(logfile) rows = parse_stock_data(lines) rows = (row for row in rows if row['name'] in portfolio) #rows = filter_symbols(rows, portfolio) import tableformat formatter = tableformat.create_formatter(fmt) formatter.headings(['Name', 'Price', 'Change']) for row in rows: rowdata = [row['name'], str(row['price']), str(row['change'])] formatter.row(rowdata)
ex 8.2 """ from structure import Structure from validate import String, Integer, Float class Ticker(Structure): name = String() price = Float() date = String() time = String() change = Float() open = Float() high = Float() low = Float() volume = Integer() if __name__ == '__main__': from follow import follow import csv from tableformat import create_formatter, print_table formatter = create_formatter('text') lines = follow('Data/stocklog.csv') rows = csv.reader(lines) records = (Ticker.from_row(row) for row in rows) negative = (rec for rec in records if rec.change < 0) print_table (negative, ['name', 'price','change'], formatter)