def extract(_file, password): header_pattern = re.compile(constants.BANDHAN_BANK_HEADER_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = { constants.TRANSACTIONS_STR: [] } is_transaction_started = False acc_details = '' i = 0 existing_desc = '' while i < len(file_content): line = file_content[i] if is_transaction_started: existing_desc = process_transaction(json_formatted_data, line, existing_desc, constants.BANDHAN_BANK_TRANSACTION_REGEX_TWO, constants.BANDHAN_BANK_DESC_REGEX) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details(json_formatted_data, acc_details, constants.BANDHAN_BANK_ACCOUNT_DETAILS_REGEX_TWO) else: acc_details += line + '\n' i = i + 1 j = len(json_formatted_data[constants.TRANSACTIONS_STR]) - 1 while j >= 0: opening_balance = bsr_utils.get_rev_opening_balance(j, json_formatted_data) transaction_type = bsr_utils.get_transaction_type(opening_balance, json_formatted_data[constants.TRANSACTIONS_STR][j][ constants.CLOSING_BALANCE_STR]) json_formatted_data[constants.TRANSACTIONS_STR][j][constants.TRANSACTION_TYPE_STR] = transaction_type j -= 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.CANARA_BANK_HEADER_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' for line in file_content: if is_transaction_started: process_transaction(json_formatted_data, line, constants.CANARA_BANK_TRANSACTION_REGEX, constants.CANARA_BANK_DESC_REGEX, constants.CANARA_BANK_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details( json_formatted_data, acc_details, constants.CANARA_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' j = len(json_formatted_data[constants.TRANSACTIONS_STR]) - 1 while j >= 0: opening_balance = bsr_utils.get_rev_opening_balance( j, json_formatted_data) transaction_type = bsr_utils.get_transaction_type( opening_balance, json_formatted_data[constants.TRANSACTIONS_STR][j] [constants.CLOSING_BALANCE_STR]) json_formatted_data[constants.TRANSACTIONS_STR][j][ constants.TRANSACTION_TYPE_STR] = transaction_type j -= 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.SYNDICATE_BANK_HEADER_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = { constants.TRANSACTIONS_STR: [] } is_transaction_started = False acc_details = '' index = 0 if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while index < len(file_content): line = file_content[index] if is_transaction_started: process_transaction(json_formatted_data, line, constants.SYNDICATE_BANK_TRANSACTION_REGEX, constants.FEDERAL_BANK_DESC_REGEX, constants.SYNDICATE_BANK_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True index += 1 bsr_utils.put_custum_acc_details(json_formatted_data, acc_details, constants.SYNDICATE_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' index = index + 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.SCH_BANK_HEADER_REGEX) file_end_patterns = [ re.compile(regex) for regex in constants.SCH_BANK_STATEMENT_END_REGEX ] file_content = bsr_utils.get_file_content(_file, password) date = None json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' for line in file_content: if bsr_utils.is_ignorable(file_end_patterns, line): is_transaction_started = False elif is_transaction_started: date = process_transaction(date, json_formatted_data, line, constants.SCH_BANK_TRANSACTION_REGEX, constants.SCH_BANK_DATE_CHANGE_REGEX, constants.SCH_BANK_DESC_REGEX, constants.SCH_BANK_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True if len(json_formatted_data[constants.TRANSACTIONS_STR]) == 0: bsr_utils.put_acc_details( json_formatted_data, acc_details, constants.SCH_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.YES_BANK_HEADER_REGEX) file_end_pattern = re.compile(constants.YES_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' i = 0 if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while i < len(file_content): line = file_content[i] if file_end_pattern.match(line): json_formatted_data.update({ constants.OPENING_BALANCE_STR: file_end_pattern.match(line).group( constants.OPENING_BALANCE_STR) }) break elif is_transaction_started: process_transaction(json_formatted_data, line, constants.YES_BANK_TRANSACTION_REGEX, constants.YES_BANK_DESC_REGEX, constants.YES_BANK_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details(json_formatted_data, acc_details, constants.YES_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' i += 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.MAHARASHTRA_BANK_HEADER_REGEX) file_end_pattern = re.compile( constants.MAHARASHTRA_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' existing_desc = '' i = 0 if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while i < len(file_content): line = file_content[i] if file_end_pattern.match(line): break if is_transaction_started: existing_desc = process_transaction( json_formatted_data, i, existing_desc, constants.MAHARASHTRA_BANK_TRANSACTION_REGEX, file_content, constants.MAHARASHTRA_BANK_DESC_REGEX, constants.MAHARASHTRA_BANK_IGNORABLE_REGEXS) elif header_pattern.search(line): is_transaction_started = True bsr_utils.put_acc_details( json_formatted_data, acc_details, constants.MAHARASHTRA_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' i += 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.UNITED_BANK_HEADER_REGEX) file_end_pattern = re.compile(constants.UNITED_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' i = 0 if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while i < len(file_content): line = file_content[i] if file_end_pattern.match(line): break if is_transaction_started: process_transaction(json_formatted_data, line, constants.UNITED_BANK_TRANSACTION_REGEX, constants.FEDERAL_BANK_DESC_REGEX) elif header_pattern.match(line): is_transaction_started = True i += 1 put_opening_balance(json_formatted_data, file_content[i]) bsr_utils.put_custum_acc_details( json_formatted_data, acc_details, constants.UNITED_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' i = i + 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.SBI_BANK_HEADER_REGEX) file_end_pattern = re.compile(constants.SBI_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' for line in file_content: if file_end_pattern.match(line): break elif is_transaction_started: process_transaction(json_formatted_data, line, constants.SBI_BANK_TRANSACTION_REGEX, constants.SBI_BANK_DESC_REGEX, constants.SBI_BANK_DESC_WITH_DATE_REGEX, constants.SBI_BANK_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details(json_formatted_data, acc_details, constants.SBI_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.KOTAK_BANK_HEADER_REGEX_TWO) file_end_pattern = re.compile(constants.KOTAK_BANK_STATEMENT_END_REGEX_TWO) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' line_index = len(file_content) - 1 while line_index > 0: line = file_content[line_index] if file_end_pattern.match(line): line = file_content[line_index] json_formatted_data.update( {constants.OPENING_BALANCE_STR: line.split()[-1]}) break line_index -= 1 line_index = 0 if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while line_index < len(file_content): line = file_content[line_index] if file_end_pattern.match(line): break elif is_transaction_started: process_transaction(json_formatted_data, line, constants.KOTAK_BANK_TRANSACTION_REGEX_TWO, constants.KOTAK_BANK_DESC_REGEX, constants.KOTAK_BANK_IGNORABLE_REGEXS_TWO) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details( json_formatted_data, acc_details, constants.KOTAK_BANK_ACCOUNT_DETAILS_REGEX_TWO) line_index -= 1 else: acc_details += line + '\n' line_index += 1 j = len(json_formatted_data[constants.TRANSACTIONS_STR]) - 1 while j >= 0: opening_balance = bsr_utils.get_rev_opening_balance( j, json_formatted_data) transaction_type = bsr_utils.get_transaction_type( opening_balance, json_formatted_data[constants.TRANSACTIONS_STR][j] [constants.CLOSING_BALANCE_STR]) json_formatted_data[constants.TRANSACTIONS_STR][j][ constants.TRANSACTION_TYPE_STR] = transaction_type j -= 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.RBL_BANK_HEADER_REGEX) file_end_pattern = re.compile(constants.RBL_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' i = len(file_content) - 1 while i > 0: if 'Opening Balance:' in file_content[i]: json_formatted_data[ constants.OPENING_BALANCE_STR] = file_content[i].split()[3] break i -= 1 i = 0 if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while i < len(file_content): line = file_content[i] if file_end_pattern.match(line): break elif is_transaction_started: process_transaction(json_formatted_data, i, file_content, constants.RBL_BANK_TRANSACTION_REGEX_1, constants.RBL_BANK_TRANSACTION_REGEX_2, constants.RBL_BANK_DESC_REGEX, constants.RBL_BANK_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details(json_formatted_data, acc_details, constants.RBL_BANK_ACCOUNT_DETAILS_REGEX) if "name" not in json_formatted_data: bsr_utils.put_acc_details( json_formatted_data, acc_details, constants.RBL_BANK_ACCOUNT_DETAILS_REGEX_TWO) else: acc_details += line + '\n' i += 1 j = len(json_formatted_data[constants.TRANSACTIONS_STR]) - 1 while j >= 0: opening_balance = bsr_utils.get_rev_opening_balance( j, json_formatted_data) transaction_type = bsr_utils.get_transaction_type( opening_balance, json_formatted_data[constants.TRANSACTIONS_STR][j] [constants.CLOSING_BALANCE_STR]) json_formatted_data[constants.TRANSACTIONS_STR][j][ constants.TRANSACTION_TYPE_STR] = transaction_type j -= 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.INDUSLAND_BANK_HEADER_REGEX) file_end_pattern = re.compile(constants.INDUSLAND_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False transaction_flag = False acc_details = '' transaction_pattern = re.compile( constants.INDUSLAND_BANK_TRANSACTION_REGEX) ignorable_patterns = [ re.compile(ignorable_regex) for ignorable_regex in constants.INDUSLAND_BANK_IGNORABLE_REGEXS ] if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' for line in file_content: if file_end_pattern.match(line): break if bsr_utils.is_ignorable(ignorable_patterns, line): transaction_flag = False continue elif is_transaction_started and transaction_flag: process_transaction(json_formatted_data, line, constants.INDUSLAND_BANK_TRANSACTION_REGEX, constants.INDUSLAND_BANK_DESC_REGEX, constants.INDUSLAND_BANK_IGNORABLE_REGEXS) elif is_transaction_started: if transaction_pattern.match(line): transaction_flag = True process_transaction(json_formatted_data, line, constants.INDUSLAND_BANK_TRANSACTION_REGEX, constants.INDUSLAND_BANK_DESC_REGEX, constants.INDUSLAND_BANK_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details( json_formatted_data, acc_details, constants.INDUSLAND_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.BOB_BANK_HEADER_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} transaction_pattern = re.compile(constants.BOB_BANK_TRANSACTION_REGEX) credit_transaction_pattern = re.compile( constants.BOB_BANK_CREDIT_TRANSACTION_REGEX) if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' for line in file_content: if transaction_pattern.match(line): m = transaction_pattern.match(line) if credit_transaction_pattern.match(line): json_formatted_data[ constants.OPENING_BALANCE_STR] = bsr_utils.get_opening_bal( bsr_utils.pretty_format( m.group(constants.CLOSING_BALANCE_STR)), bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)), constants.DEPOSIT_TYPE) else: json_formatted_data[ constants.OPENING_BALANCE_STR] = bsr_utils.get_opening_bal( bsr_utils.pretty_format( m.group(constants.CLOSING_BALANCE_STR)), bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)), constants.WITHDRAW_TYPE) break is_transaction_started = False acc_details = '' for line in file_content: if is_transaction_started: process_transaction(json_formatted_data, line, constants.BOB_BANK_TRANSACTION_REGEX) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details(json_formatted_data, acc_details, constants.BOB_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' return json_formatted_data
def extract(_file, password): header_pattern = re.compile(business_constants.ICICI_BANK_HEADER_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = {business_constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' i = 0 existing_desc = '' if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while i < len(file_content): line = file_content[i] if is_transaction_started: existing_desc = process_transaction( json_formatted_data, line, existing_desc, business_constants.ICICI_BANK_TRANSACTION_REGEX, business_constants.ICICI_BANK_DESC_REGEX, business_constants.ICICI_BANK_IGNORABLE_REGEXS, True) transaction_pattern = re.compile( business_constants.ICICI_BANK_TRANSACTION_REGEX) # there must be transaction and existing desc should be empty if transaction_pattern and not existing_desc: i = i + 1 line = file_content[i] existing_desc = process_transaction( json_formatted_data, line, existing_desc, business_constants.ICICI_BANK_TRANSACTION_REGEX, business_constants.ICICI_BANK_DESC_REGEX, business_constants.ICICI_BANK_IGNORABLE_REGEXS, False) elif header_pattern.match(line): i += 2 is_transaction_started = True bsr_utils.put_custum_acc_details( json_formatted_data, acc_details, business_constants.ICICI_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' i += 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.INDIAN_OVERSEAS_BANK_HEADER_REGEX) file_end_pattern = re.compile(constants.INDIAN_OVERSEAS_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = { constants.TRANSACTIONS_STR: [] } is_transaction_started = False acc_details = '' i = 0 if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' while i < len(file_content): if i == 0: i = i + 2 line = file_content[i] if file_end_pattern.match(line): break elif is_transaction_started: process_transaction(json_formatted_data, i, constants.INDIAN_OVERSEAS_BANK_TRANSACTION_REGEX, file_content, constants.INDIAN_OVERSEAS_BANK_DESC_REGEX) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_custum_acc_details(json_formatted_data, acc_details, constants.INDIAN_OVERSEAS_BANK_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' i = i + 1 j = len(json_formatted_data[constants.TRANSACTIONS_STR]) - 2 while j >= 0: opening_balance = bsr_utils.get_rev_opening_balance(j, json_formatted_data) transaction_type = bsr_utils.get_custom_transaction_type(opening_balance, json_formatted_data[constants.TRANSACTIONS_STR][j][ constants.CLOSING_BALANCE_STR]) json_formatted_data[constants.TRANSACTIONS_STR][j + 1][constants.TRANSACTION_TYPE_STR] = transaction_type j -= 1 return json_formatted_data
def extract(_file, password): header_pattern = re.compile(constants.HDFC_BANK_HEADER_REGEX) file_end_pattern = re.compile(constants.HDFC_BANK_STATEMENT_END_REGEX) file_content = bsr_utils.get_file_content(_file, password) json_formatted_data = { constants.TRANSACTIONS_STR: [] } is_transaction_started = False acc_details = '' existing_desc = '' if file_content == 'wrongpassword': return 'wrongpassword' elif file_content == 'pdfnotreadable': return 'pdfnotreadable' i = len(file_content) - 1 while i > 0: line = file_content[i] if file_end_pattern.match(line): line = file_content[i + 1] json_formatted_data.update( {constants.OPENING_BALANCE_STR: line.split()[0]}) break i -= 1 i = 0 while i < len(file_content): line = file_content[i] if file_end_pattern.match(line): pass elif is_transaction_started: existing_desc = process_transaction(json_formatted_data, line, existing_desc, constants.HDFC_BANK_TWO_TRANSACTION_REGEX, constants.HDFC_BANK_TWO_DESC_REGEX, constants.HDFC_BANK_TWO_IGNORABLE_REGEXS) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details(json_formatted_data, acc_details, constants.HDFC_BANK_TWO_ACCOUNT_DETAILS_REGEX) else: acc_details += line + '\n' i += 1 return json_formatted_data
def extract(file, password): header_pattern = re.compile(constants.BOI_BANK_HEADER_REGEX_TWO) file_end_pattern = re.compile(constants.BOI_BANK_STATEMENT_END_REGEX_TWO) file_content = bsr_utils.get_file_content(file, password) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' for line in file_content: if file_end_pattern.match(line): break elif is_transaction_started: process_transaction(json_formatted_data, line, constants.BOI_BANK_TRANSACTION_REGEX_TWO, constants.BOI_BANK_DESC_REGEX) elif header_pattern.match(line): is_transaction_started = True bsr_utils.put_acc_details( json_formatted_data, acc_details, constants.BOI_BANK_ACCOUNT_DETAILS_REGEX_TWO) else: acc_details += line + '\n' return json_formatted_data
def extract(file, header_regex, file_end_regex, account_regex, transaction_regex, desc_regex, ignorable_regexes): header_pattern = re.compile(header_regex) file_end_pattern = re.compile(file_end_regex) file_content = bsr_utils.get_file_content(file) json_formatted_data = {constants.TRANSACTIONS_STR: []} is_transaction_started = False acc_details = '' for line in file_content: if file_end_pattern.match(line): break elif is_transaction_started: process_transaction(json_formatted_data, line, transaction_regex, desc_regex, ignorable_regexes) elif header_pattern.match(line): is_transaction_started = True put_acc_details(json_formatted_data, acc_details, account_regex) else: acc_details += line + '\n' return json_formatted_data