Example #1
0
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)
Example #2
0
def inventory_cost(filename):
    #ive = read_inventory(filename)
    inventory = read_inventory(filename)
    return inventory.total_cost
        yield [row[idx] for idx in indices]


def parse_product_data(lines):
    rows = csv.reader(lines)
    rows = select_columns(rows, [0, 1, 4])
    # Equivalent Generator expression below select_columns.
    #rows = ( [row[idx] for idx in [0,1,4]] for row in rows )

    rows = convert_types(rows, [str, float, float])
    # Equivalent Generator expression below for convert_types
    #rows = ( [ func(val) for func, val in zip([str,float,float],row) ] for row in rows )

    headers = ['name', 'price', 'change']
    #rows = make_dicts(rows,headers)
    rows = (dict(zip(headers, row)) for row in rows)

    return rows


if __name__ == '__main__':
    inventory = read_inventory('Data/inventory.csv')

    lines = follow('Data/marketlog.csv')
    rows = parse_product_data(lines)

    #rows = filter_names(rows,inventory)
    rows = (row for row in rows if row['name'] in inventory)

    for row in rows:
        print(row)
Example #4
0
def inventory_cost(file_name):
    inventory = read_inventory(file_name)

    return inventory.total_cost