def process_transaction(json_formatted_data, line, existing_desc,
                        transaction_regex, desc_regex, ignorable_regexes):
    transaction_pattern = re.compile(transaction_regex)
    desc_pattern = re.compile(desc_regex)
    ignorable_patterns = [
        re.compile(ignorable_regex) for ignorable_regex in ignorable_regexes
    ]
    m = transaction_pattern.match(line)

    if transaction_pattern.match(line):
        opening_balance = bsr_utils.get_opening_balance(json_formatted_data)
        transaction_type = bsr_utils.get_transaction_type(
            opening_balance,
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR)))
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR:
            existing_desc +
            bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.TYPE_STR:
            transaction_type,
            constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
        existing_desc = ''
    elif bsr_utils.is_ignorable(ignorable_patterns, line):
        pass
    elif desc_pattern.match(line):
        existing_desc = process_desc(desc_pattern, line, existing_desc)
    return existing_desc
def process_transaction(json_formatted_data, line, transaction_regex,
                        desc_regex):
    transaction_pattern = re.compile(transaction_regex)
    desc_pattern = re.compile(desc_regex)
    m = transaction_pattern.match(line)

    if transaction_pattern.match(line):
        opening_balance = bsr_utils.get_opening_balance(json_formatted_data)
        transaction_type = bsr_utils.get_transaction_type(
            opening_balance,
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR)))
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR:
            bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.TYPE_STR:
            transaction_type,
            constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
    elif desc_pattern.match(line):
        process_desc(json_formatted_data, desc_pattern, line)
示例#3
0
def process_transaction(json_formatted_data, line, transaction_regex,
                        desc_regex, ignorable_regexes):
    transaction_pattern = re.compile(transaction_regex)
    desc_pattern = re.compile(desc_regex)
    ignorable_patterns = [
        re.compile(ignorable_regex) for ignorable_regex in ignorable_regexes
    ]
    m = transaction_pattern.match(line)

    if transaction_pattern.match(line):
        withdraw = float(
            bsr_utils.pretty_format(m.group(
                constants.WITHDRAW_AMOUNT_STR)).replace(',', ''))
        deposit = float(
            bsr_utils.pretty_format(m.group(
                constants.DEPOSIT_AMOUNT_STR)).replace(',', ''))
        amount = withdraw + deposit
        transaction_type = get_transaction(deposit)
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR:
            bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.TYPE_STR:
            transaction_type,
            constants.AMOUNT_STR:
            amount,
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
    elif bsr_utils.is_ignorable(ignorable_patterns, line):
        pass
    elif desc_pattern.match(line):
        process_desc(json_formatted_data, desc_pattern, line)
def process_transaction(json_formatted_data, line, transaction_regex,
                        desc_regex, ignorable_regexes):
    transaction_pattern = re.compile(transaction_regex)
    desc_pattern = re.compile(desc_regex)
    ignorable_patterns = [
        re.compile(ignorable_regex) for ignorable_regex in ignorable_regexes
    ]
    m = transaction_pattern.search(line)
    if transaction_pattern.search(line):
        transaction_type = get_transaction_type(
            bsr_utils.pretty_format(
                m.group(business_constants.TRANSACTION_TYPE_STR)))
        json_formatted_data[business_constants.TRANSACTIONS_STR].append({
            business_constants.DATE_STR:
            bsr_utils.pretty_format(m.group(business_constants.DATE_STR)),
            business_constants.DESCRIPTION_STR:
            bsr_utils.pretty_format(m.group(
                business_constants.DESCRIPTION_STR)),
            business_constants.TYPE_STR:
            transaction_type,
            business_constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(business_constants.AMOUNT_STR)),
            business_constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(
                m.group(business_constants.CLOSING_BALANCE_STR))
        })
    elif bsr_utils.is_ignorable(ignorable_patterns, line):
        pass
    elif desc_pattern.search(line):
        process_desc(json_formatted_data, desc_pattern, line)
def process_desc_with_date(json_formatted_data, desc_pattern, line):
    m = desc_pattern.match(line)
    description_extended = m.group(constants.DESCRIPTION_STR)
    date_extended = m.group(constants.DATE_STR)
    value_date_extended = m.group(constants.VALUE_DATE_STR)
    json_formatted_data[constants.TRANSACTIONS_STR][-1][
        constants.
        DESCRIPTION_STR] += ' ' + bsr_utils.pretty_format(description_extended)
    json_formatted_data[constants.TRANSACTIONS_STR][-1][
        constants.DATE_STR] += ' ' + bsr_utils.pretty_format(date_extended)
    json_formatted_data[constants.TRANSACTIONS_STR][-1][
        constants.
        VALUE_DATE_STR] += ' ' + bsr_utils.pretty_format(value_date_extended)
def process_transaction(json_formatted_data, i, transaction_regex, file_content, desc_regex):
    line = file_content[i]
    transaction_pattern = re.compile(transaction_regex)
    desc_pattern = re.compile(desc_regex)
    m = transaction_pattern.match(line)
    if transaction_pattern.match(line):
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR: bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR: bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.AMOUNT_STR: bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR: bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
    elif desc_pattern.match(line):
        process_desc(json_formatted_data, desc_pattern, line)
def process_desc(json_formatted_data, desc_pattern, line):
    m = desc_pattern.match(line)
    groups = m.groups()
    if constants.OPENING_BALANCE_STR in groups:
        opening_balance = m.group(constants.OPENING_BALANCE_STR)
        if opening_balance != '':
            json_formatted_data[constants.TRANSACTIONS_STR][-1][
                constants.OPENING_BALANCE_STR] += bsr_utils.pretty_format(
                    opening_balance)
    if constants.DESCRIPTION_STR in groups:
        description_extended = m.group(constants.DESCRIPTION_STR)
        if description_extended != '':
            json_formatted_data[constants.TRANSACTIONS_STR][-1][
                constants.DESCRIPTION_STR] += ' ' + bsr_utils.pretty_format(
                    description_extended)
def process_transaction(json_formatted_data, line, transaction_regex):
    transaction_pattern = re.compile(transaction_regex)
    m = transaction_pattern.match(line)
    if transaction_pattern.match(line):
        transaction_type = get_transaction_type(bsr_utils.pretty_format(m.group(constants.TRANSACTION_TYPE_STR)))
        if constants.OPENING_BALANCE_STR not in json_formatted_data:
            json_formatted_data[constants.OPENING_BALANCE_STR] = bsr_utils.get_opening_bal(
                m.group(constants.CLOSING_BALANCE_STR),
                m.group(constants.AMOUNT_STR), transaction_type)
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR: bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR: bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.TYPE_STR: transaction_type,
            constants.AMOUNT_STR: bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR: bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
def process_desc(json_formatted_data, desc_pattern, line):
    m = desc_pattern.match(line)
    description_extended = m.group(constants.DESCRIPTION_STR)
    if (len(json_formatted_data[constants.TRANSACTIONS_STR]) > 0):
        json_formatted_data[constants.TRANSACTIONS_STR][-1][
            constants.DESCRIPTION_STR] += ' ' + bsr_utils.pretty_format(
                description_extended)
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
示例#11
0
def process_transaction(json_formatted_data, i, existing_desc,
                        transaction_regex, file_content, desc_regex,
                        ignorable_regexes):
    line = file_content[i]
    return_statement = False
    Description_value = ''
    transaction_pattern = re.compile(transaction_regex)
    desc_pattern = re.compile(desc_regex)
    ignorable_patterns = [
        re.compile(ignorable_regex) for ignorable_regex in ignorable_regexes
    ]
    m = transaction_pattern.match(line)

    if transaction_pattern.match(line):
        if (len(bsr_utils.pretty_format(m.group(constants.DATE_STR))) >
                0) and len(
                    bsr_utils.pretty_format(m.group(
                        constants.DESCRIPTION_STR))) > 0:
            Description_value = bsr_utils.pretty_format(
                m.group(constants.DESCRIPTION_STR))
        else:
            Description_value = ''
            return_statement = True
        opening_balance = bsr_utils.get_opening_balance(json_formatted_data)
        transaction_type = bsr_utils.get_transaction_type(
            opening_balance,
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR)))
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            # constants.DESCRIPTION_STR: bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.DESCRIPTION_STR:
            Description_value,
            constants.TYPE_STR:
            transaction_type,
            constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
        if return_statement:
            return existing_desc
    elif bsr_utils.is_ignorable(ignorable_patterns, line):
        pass
    elif desc_pattern.match(line):
        if existing_desc is None or existing_desc == '':
            existing_desc = existing_desc + line
        else:
            process_desc_custum(json_formatted_data, desc_pattern, line,
                                existing_desc)
            existing_desc = ''
    return existing_desc
示例#12
0
def process_transaction(json_formatted_data, i, file_content,
                        transaction_regex_1, transaction_regex_2, desc_regex,
                        ignorable_regexes):
    line = file_content[i]
    transaction_pattern_1 = re.compile(transaction_regex_1)
    transaction_pattern_2 = re.compile(transaction_regex_2)
    desc_pattern = re.compile(desc_regex)
    ignorable_patterns = [
        re.compile(ignorable_regex) for ignorable_regex in ignorable_regexes
    ]
    m = transaction_pattern_1.match(line)

    if transaction_pattern_1.match(line):
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR:
            bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
    elif transaction_pattern_2.match(line):
        m = transaction_pattern_2.match(line)
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR:
            bsr_utils.pretty_format(file_content[i - 1]) + ' ' +
            bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
    elif bsr_utils.is_ignorable(ignorable_patterns, line):
        pass
    elif desc_pattern.match(line):
        process_desc(json_formatted_data, desc_pattern, line)
def process_transaction(json_formatted_data, i, transaction_regex, file_content):
    line = file_content[i]
    transaction_pattern = re.compile(transaction_regex)
    m = transaction_pattern.match(line)

    if transaction_pattern.match(line):
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR: bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR: bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.AMOUNT_STR: bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR: bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })

        if bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)) == '':
            json_formatted_data[constants.TRANSACTIONS_STR][-1][
                constants.DESCRIPTION_STR] += bsr_utils.pretty_format(file_content[i - 1]) + ' ' + \
                                              bsr_utils.pretty_format(file_content[i + 1])
示例#14
0
def process_transaction(json_formatted_data, line, existing_desc,
                        transaction_regex, desc_regex):
    return_statement = False
    Description_value = ''
    transaction_pattern = re.compile(transaction_regex)
    # desc_pattern = re.compile(desc_regex)
    m = transaction_pattern.match(line)
    if transaction_pattern.match(line):
        if (len(bsr_utils.pretty_format(m.group(constants.DATE_STR))) >
                0) and len(
                    bsr_utils.pretty_format(m.group(
                        constants.DESCRIPTION_STR))) > 0:
            Description_value = bsr_utils.pretty_format(
                m.group(constants.DESCRIPTION_STR))
        else:
            # Description_value = existing_desc + bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR))
            Description_value = ''
            return_statement = True
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR:
            Description_value,
            constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
        existing_desc = ''
        if return_statement:
            return existing_desc

    # elif desc_pattern.match(line):
    #     if(len(json_formatted_data[constants.TRANSACTIONS_STR]) > 0):
    #         if len(json_formatted_data[constants.TRANSACTIONS_STR][-1][constants.DESCRIPTION_STR]) == 0 :
    #             print (line)
    #             process_desc_custum(json_formatted_data,desc_pattern,line)
    #         else:
    #             # print ('---line')
    #             # print (line)
    #             # print ('---dis')
    #             # print (json_formatted_data[constants.TRANSACTIONS_STR][-1][constants.DESCRIPTION_STR])
    #             existing_desc = process_desc(desc_pattern, line, existing_desc)
    #             # for back
    #     else:

    #         process_desc_custum(json_formatted_data,desc_pattern,line)

    return existing_desc
def process_transaction(json_formatted_data, line, existing_desc, transaction_regex, desc_regex):
    return_statement = False
    Description_value = ''
    transaction_pattern = re.compile(transaction_regex)
    m = transaction_pattern.match(line)
    if transaction_pattern.match(line):
        if (len(bsr_utils.pretty_format(m.group(constants.DATE_STR))) > 0) and len(
                bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR))) > 0:
            Description_value = bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR))
        else:
            Description_value = ''
            return_statement = True
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR: bsr_utils.pretty_format(m.group(constants.DATE_STR)),
            constants.DESCRIPTION_STR: Description_value,
            constants.AMOUNT_STR: bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR: bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
        existing_desc = ''
        if return_statement:
            return existing_desc
    return existing_desc
def process_desc_custum(desc_pattern, line, existing_desc):
    line = line.strip()
    if line != '':
        m = desc_pattern.match(line)
        existing_desc += ' ' + bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR))
    return existing_desc
def process_desc(desc_pattern, line, existing_desc):
    m = desc_pattern.match(line)
    existing_desc += ' ' + bsr_utils.pretty_format(
        m.group(business_constants.DESCRIPTION_STR))
    return existing_desc
示例#18
0
def process_desc(json_formatted_data, desc_pattern, line):
    m = desc_pattern.match(line)
    json_formatted_data[constants.TRANSACTIONS_STR][-1][
        constants.DESCRIPTION_STR] += ' ' + bsr_utils.pretty_format(
            m.group(constants.DESCRIPTION_STR))
示例#19
0
def process_transaction(date, json_formatted_data, line, transaction_regex,
                        date_change_regex, desc_regex, ignorable_regexes):
    transaction_pattern = re.compile(transaction_regex)
    date_change_pattern = re.compile(date_change_regex)
    desc_pattern = re.compile(desc_regex)
    ignorable_patterns = [
        re.compile(ignorable_regex) for ignorable_regex in ignorable_regexes
    ]
    m = transaction_pattern.match(line)
    if date_change_pattern.match(line):
        m = date_change_pattern.match(line)
        date = m.group(constants.DATE_STR)
        if transaction_pattern.match(line):
            m = transaction_pattern.match(line)
            opening_balance = bsr_utils.get_opening_balance(
                json_formatted_data)
            transaction_type = bsr_utils.get_transaction_type(
                opening_balance,
                bsr_utils.pretty_format(m.group(
                    constants.CLOSING_BALANCE_STR)))
            json_formatted_data[constants.TRANSACTIONS_STR].append({
                constants.DATE_STR:
                bsr_utils.pretty_format(date),
                constants.DESCRIPTION_STR:
                bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
                constants.TYPE_STR:
                transaction_type,
                constants.AMOUNT_STR:
                bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
                constants.CLOSING_BALANCE_STR:
                bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
            })
        elif constants.OPENING_BALANCE_STR not in json_formatted_data:
            json_formatted_data[
                constants.OPENING_BALANCE_STR] = bsr_utils.pretty_format(
                    m.group(constants.AMOUNT_STR))
    elif transaction_pattern.match(line):
        opening_balance = bsr_utils.get_opening_balance(json_formatted_data)
        transaction_type = bsr_utils.get_transaction_type(
            opening_balance,
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR)))
        json_formatted_data[constants.TRANSACTIONS_STR].append({
            constants.DATE_STR:
            bsr_utils.pretty_format(date),
            constants.DESCRIPTION_STR:
            bsr_utils.pretty_format(m.group(constants.DESCRIPTION_STR)),
            constants.TYPE_STR:
            transaction_type,
            constants.AMOUNT_STR:
            bsr_utils.pretty_format(m.group(constants.AMOUNT_STR)),
            constants.CLOSING_BALANCE_STR:
            bsr_utils.pretty_format(m.group(constants.CLOSING_BALANCE_STR))
        })
    elif bsr_utils.is_ignorable(ignorable_patterns, line):
        pass
    elif desc_pattern.match(line):
        process_desc(json_formatted_data, desc_pattern, line)
    # print json_formatted_data
    return date