예제 #1
0
    def test_convert_configured(self):
        inputfname = os.path.join(self.tmpdir, "input")
        outputfname = os.path.join(self.tmpdir, "output")
        args = mock.Mock(type="test", input=inputfname, output=outputfname)

        config = {"test": {"plugin": "sample"}}

        parser = mock.Mock()
        parser.parse.return_value = statement.Statement()

        sample_plugin = mock.Mock()
        sample_plugin.get_parser.return_value = parser

        configpatch = mock.patch("ofxstatement.configuration.read",
                                 return_value=config)

        pluginpatch = mock.patch("ofxstatement.plugin.get_plugin",
                                 return_value=sample_plugin)

        with configpatch, pluginpatch:
            ret = tool.convert(args)

        self.assertEqual(ret, 0)
        self.assertEqual(self.log.getvalue().splitlines(),
                         ["INFO: Conversion completed: %s" % inputfname])
예제 #2
0
 def __init__(self, fin):
     super().__init__()
     self.statement = statement.Statement()
     self.fin = fin
     # Skip 1st row with column's headers
     self.fin.readline()
     self.cur_record = 1
예제 #3
0
 def __init__(self, fin):
     self.date_format = '%d.%m.%y'
     self.statement = statement.Statement()
     self.fin = fin
     # Skip 1st row with column's headers
     self.fin.readline()
     self.cur_record = 1
     self.user_date = False
예제 #4
0
    def parse(self):
        """Main entry point for parsers

        super() implementation will call to split_records and parse_record to
        process the file.
        """
        workbook = xlrd.open_workbook(self.filename)
        sheet = workbook.sheet_by_index(0)
        heading, rows = [], []

        # split heading from current statement
        for rowidx in range(sheet.nrows):
            row = sheet.row_values(rowidx)
            if self.th_separator_idx > 0:
                if row[0] != '' and not str(row[0]).startswith(
                        self.common_footer_marker):
                    rows.append(row)
            else:
                heading.append(row)

            # guess sheet tpl type
            for name, tpl in self.tpl.items():
                if row[0] == tpl['th'][0]:
                    self.th_separator_idx = rowidx
                    self.cur_tpl = name

        # issue #1: check if the file has the "Money Map" extra field
        if self.cur_tpl == 'savings' and heading[-1][-1] == self.tpl[
                'savings']['extra_field']:
            self.tpl['savings']['th'].append(
                self.tpl['savings']['extra_field'])
            self.extra_field = True

        # issue #2: some cards statements could miss "Tipo Spesa" and "Tipo Rimborso" columns
        elif self.cur_tpl == 'cards' and heading[-1][3] == self.tpl['cards'][
                'th'][5]:
            self.tpl['cards']['th'].remove("Tipo spesa")
            self.tpl['cards']['th'].remove("Tipo rimborso")
            self.tpl['cards']['th'].append("")
            self.tpl['cards']['th_row'] = 1
            self.tpl['cards']['amount_field'] = 4

        self.validate(heading)

        if self.cur_tpl == 'savings':
            account_id = sheet.cell_value(0, 0).replace(
                self.tpl[self.cur_tpl]['account_id_str'], '')
        elif self.cur_tpl == 'cards':
            account_id = sheet.cell_value(
                self.tpl['cards']['th_row'],
                2).replace(self.tpl[self.cur_tpl]['account_id_str'], '-')

        self.statement = statement.Statement(bank_id=self.bank_id,
                                             account_id=account_id,
                                             currency=self.currency)

        self.rows = rows
        return super(FinecoStatementParser, self).parse()
예제 #5
0
    def parse(self):
        """Main entry point for parsers

        super() implementation will call to split_records and parse_record to
        process the file.
        """
        workbook = xlrd.open_workbook(self.filename)
        sheet = workbook.sheet_by_index(0)
        heading, rows = [], []

        for rowidx in range(sheet.nrows):
            row = sheet.row_values(rowidx)

            # issue #5 and #3: dates might be formatted as excel dates (floats) rather than strings
            if type(row[0]) is float:
                row[0] = datetime.strftime(xlrd.xldate_as_datetime(row[0], 0), self.date_format)

            # split heading from current statement
            if self.th_separator_idx > 0:
                if row[0] != '' and not row[0].startswith(self.common_footer_marker):
                    rows.append(row)
            else:
                heading.append(row)

            # guess sheet tpl type
            for name, tpl in self.tpl.items():
                if row[0] == tpl['th'][0]:
                    self.th_separator_idx = rowidx
                    self.cur_tpl = name

        # issue #1: check if the file has the "Money Map" extra field
        if 'extra_field' in self.tpl[self.cur_tpl] and heading[-1][-1] == self.tpl[self.cur_tpl]['extra_field']:
            self.tpl[self.cur_tpl]['th'].append(self.tpl[self.cur_tpl]['extra_field'])
            self.extra_field = True

        # issue #2: some cards statements could miss "Tipo Spesa" and "Tipo Rimborso" columns
        elif self.cur_tpl == 'cards' and heading[-1][3] == self.tpl['cards']['th'][5]:
            self.tpl['cards']['th'].remove("Tipo spesa")
            self.tpl['cards']['th'].remove("Tipo rimborso")
            self.tpl['cards']['th'].append("")
            self.tpl['cards']['amount_field'] = 4

        self.validate(heading)

        row = self.tpl[self.cur_tpl]['account_id_pos'][0]
        col = self.tpl[self.cur_tpl]['account_id_pos'][1]
        account_id = sheet.cell_value(row, col).replace(self.tpl[self.cur_tpl]['account_id_str'], '')

        self.statement = statement.Statement(
            bank_id = self.bank_id,
            account_id = account_id,
            currency = self.currency
        )

        self.rows = rows
        return super(FinecoStatementParser, self).parse()
예제 #6
0
    def __init__(self, fin):
        self.statement = statement.Statement()
        self.internal = {}
        self.fin = fin

        self.currentState = 'init'

        state = ParserState('init', self)
        state.addMatcher(u"^.*ВАЛЮТА СЧЕТА.*$", 'currency')

        state = ParserState('currency', self)
        state.addMatcher("^\s*(\w{3})\s*$", 'begin_balance',
                         self.extractCurrency)

        state = ParserState('begin_balance', self)
        state.addMatcher(
            u"^ОСТАТОК НА НАЧАЛО ПЕРИОДА:\s*(\d+\.\d{2})(\+)?\s*$",
            'table_header', self.extractBeginBalance)

        state = ParserState('table_header', self)
        state.addMatcher("^[-+]{80,}$", 'table_header2')

        state = ParserState('table_header2', self)
        state.addMatcher("^[-+]{80,}$", 'transaction')

        state = ParserState('transaction', self)
        state.addMatcher("^[-+]{80,}$", 'end_balance')
        state.addMatcher(
            u"^(.*)\s*(\d{2}[А-Я]{3})\s+(\d{2}[А-Я]{3}\d{2})\s+\d{6}\s+(.*)\s\w{3}\s+\d*\.\d{2}\s+(\d*\.\d{2})(CR)?\s*$",
            None, self.extractTransaction)
        state.addMatcher(
            u"^(.*)\s*(\d{2}[А-Я]{3})\s+(\d{2}[А-Я]{3}\d{2})\s+\d{6}\s+(КОМИССИЯ)\s+(\d*\.\d{2})(CR)?\s*$",
            None, self.extractTransaction)
        state.addMatcher(
            u"^(.*)\s*(\d{2}[А-Я]{3})\s+(\d{2}[А-Я]{3}\d{2})\s+\d{6}\s+(.*)\s(\d*\.\d{2})(CR)?\s*$",
            None, self.extractTransaction)
        state.addMatcher(u".*ИТОГО ПО.*")
        state.addMatcher(u"^(.+)\s*$", None, self.extractTransactionAppend)

        state = ParserState('end_balance', self)
        state.addMatcher(u"^ОСТАТОК НА КОНЕЦ ПЕРИОДА:\s*(\d+\.\d{2})\+?\s*$",
                         'table_header', self.extractEndBalance)
예제 #7
0
 def __init__(self, fin):
     super().__init__()
     self.statement = statement.Statement()
     self.fin = fin
예제 #8
0
 def __init__(self, fin):
     self.statement = statement.Statement()
     self.fin = fin
     self.user_date = False