Beispiel #1
0
def main():
    input_files = glob(os.path.join(input_path, '*.xls*'))
    print("Files to process: %d" % len(input_files))
    input_files = select_new_files(input_files, output_file)
    print("New files: %d" % len(input_files))
    if 0 == len(input_files):
        print("There is nothing to add to the existing CSV file.")
        return
    with open(output_file, 'a', encoding='utf-8') as f:
        for fpath in input_files:
            print("\t%s" % fpath)
            mex = MenuExtractor(fpath)
            menu_data = mex.menus_combined
            menu_data['File'] = os.path.basename(fpath)
            menu_data['SHA1'] = sha1sum(fpath)
            menu_data.to_csv(f, header=False, index=False)
            del mex
    # Add a header to the csv file
    df = pd.read_csv(output_file)
    df.columns = [
        'Food', 'Weight', 'Price', 'Type', 'Key', 'Date', 'File', 'SHA1'
    ]
    df.to_csv(output_file, index=False)
    print("Done.")
Beispiel #2
0
def test_menu_rows(file_path, menu_rows):
    mex = MenuExtractor(Path(file_path))
    assert mex.menus_list[0].shape[0] == menu_rows
Beispiel #3
0
def test_combined_menu_cols(file_path, menu_cols):
    mex = MenuExtractor(Path(file_path))
    assert mex.menus_combined.shape[1] == menu_cols
Beispiel #4
0
def test_menu_count(file_path, menu_num):
    mex = MenuExtractor(Path(file_path))
    assert len(mex.menus_list) == menu_num
Beispiel #5
0
def test_menu_dates(file_path, menu_dates):
    mex = MenuExtractor(Path(file_path))
    assert mex.menu_dates == menu_dates
Beispiel #6
0
def test_all_tabs(file_path, menus_num):
    mex = MenuExtractor(Path(file_path))
    assert len(mex.excel_menus) == menus_num
Beispiel #7
0
def test_read_nonexisting_files():
    with pytest.raises(FileNotFoundError):
        mex = MenuExtractor(Path('data/is_wrong/I do not exist.xlsx'))
Beispiel #8
0
def test_read_existing_files():
    try:
        mex = MenuExtractor(Path('data/Меню с 02.04 по 06.04.2018г.xls'))
    except FileNotFoundError:
        pytest.fail("Unexpected FileNotFound error.")