Exemplo n.º 1
0
def main():
    try:
        # parse command line arguments
        filename_catalog, filename_sales = _parse_command_line_parameters()
        # print(filename_catalog, filename_sales)

        # load sales data
        sales = load_sales_data(filename_sales)
        catalog_by_item_id = load_catalog_by_item_id(filename_catalog)

        # calculate and print summaries
        print_summary(sales)
        print_sales_amount_by_city(sales)
        print_sales_amount_by_category(sales, catalog_by_item_id)
        return 0
    except Exception as e:
        print("Error: " + str(e))
        raise
Exemplo n.º 2
0
def main():
    if len(sys.argv) < 4:
        print("Usage: {} <catalog-file.csv> <sales-file.csv> <output.db>".format(sys.argv[0]))
        return 2

    # TODO: check if files exist and are readable

    catalog_by_item_id = load_catalog_by_item_id(sys.argv[1])
    sales = load_sales_data(sys.argv[2])

    db_filename = sys.argv[3]

    with sqlite3.connect(db_filename, isolation_level=None) as connection:
        print("Connection opened")
        create_tables(connection)
        print("Tables created")
        import_catalog_into_db(catalog_by_item_id, connection)
        print("Catalog imported")
        import_sales_into_db(sales, connection)
Exemplo n.º 3
0
def main():
    try:
        # parse command line arguments
        filename_catalog, filename_sales = _parse_command_line_parameters()
        print(filename_catalog, filename_sales)

        # load sales data
        sales = load_sales_data(filename_sales)
        catalog_by_item_id = load_catalog_by_item_id(filename_catalog)

        # calculate and print summaries
        print_summary(sales)
        print_sales_amount_by_city(sales)
        print_sales_amount_by_categories(sales, catalog_by_item_id)

        return 0
    except Exception as e:
        print("Error: " + str(e))
        raise
Exemplo n.º 4
0
def main():
    if len(sys.argv) < 4:
        print(
            "Usage: {} <catalog-file.csv> <sales-file.csv> <output.db>".format(
                sys.argv[0]))
        return 2

    # TODO: check if files exist and are readable

    catalog_by_item_id = load_catalog_by_item_id(sys.argv[1])
    sales = load_sales_data(sys.argv[2])

    db_filename = sys.argv[3]

    with sqlite3.connect(db_filename, isolation_level=None) as connection:
        print("Connection opened")
        create_tables(connection)
        print("Tables created")
        import_catalog_into_db(catalog_by_item_id, connection)
        print("Catalog imported")
        import_sales_into_db(sales, connection)