#!/usr/bin/python # -*- coding: utf-8 -*- # __author__ = 'szhdanoff@gmail.com' import os import csv from dotenv import load_dotenv load_dotenv() APP_TOKEN = os.getenv('APP_TOKEN') POS_TOKEN = os.getenv('POS_TOKEN') MERCHANT_ID = os.getenv('MERCHANT_ID') is_prod = bool(os.getenv('PRODUCTION', False)) CURRENCY = os.getenv('CURRENCY', 'RUB') if is_prod: API_URI = 'https://pos-api.dinect.com/20130701/' else: API_URI = 'https://pos-api-ote.dinect.com/20130701/' print(is_prod, API_URI) csv_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'csv') files = [] # r=root, d=directories, f = files for r, d, f in os.walk(csv_path): for file in f: filename, file_extension = os.path.splitext(file) if file_extension == '.csv': files.append(os.path.join(r, file)) 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: 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 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') 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 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() # os.rename(f, f + '.old')