From 316499a0d348694d66aada210dfd8f882b4c8c14 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 7 Aug 2024 21:39:16 +0300 Subject: [PATCH] fixed separate reading of files --- app.py | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/app.py b/app.py index f108254..3b3d80f 100644 --- a/app.py +++ b/app.py @@ -34,28 +34,39 @@ for r, d, f in os.walk(csv_path): for f in files: with open(f + '.log', "w", encoding="utf-8") as log_file: with open(f, "r", encoding="utf-8") as csv_file: - csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 - for row in csv_reader: - if line_count == 0: - line_count += 1 - else: - try: - nickname, card, phone, summ_total, summ_discount, sum_with_discount, bonus_amount, transaction_date, transaction_time = row - print(f'Processing line {line_count}: {row}') + file_name = os.path.basename(f) + if 'users' in file_name: + print(f'Processing "users" file: {f}') + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + for row in csv_reader: + if line_count == 0: line_count += 1 - except ValueError as e: - ret = f'error in line: [{line_count}] {repr(e)}' - log_file.write(f'{ret}\n') + else: + try: + print(f'Processing line {line_count}: {row}') + nickname, full_name, card, phone, email, gender = row + line_count += 1 + except ValueError as e: + ret = f'error in line: [{line_count}] {repr(e)}' + log_file.write(f'{ret}\n') - # name, wallet, value = row[0].strip(), row[1].strip(), row[2].strip() - # value = value.replace(',', '.') - # value = value.replace(chr(160), '') - # if value == '0': - # value = '' + if 'transaction' in file_name: + print(f'Processing "transaction" file: {f}') + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + for row in csv_reader: + if line_count == 0: + line_count += 1 + else: + try: + print(f'Processing line {line_count}: {row}') + user_id, card, phone, summ_total, summ_discount, sum_with_discount, bonus_amount, transaction_date, transaction_time = row + line_count += 1 - # log_file.write(f'{wallet}{chr9}{value}{chr9}{ret}\n') - # log_file.write(f'{ret}\n') + except ValueError as e: + ret = f'error in line: [{line_count}] {repr(e)}' + log_file.write(f'{ret}\n') csv_file.close() log_file.close()