Esempio n. 1
0
    def get_history(self, account):
        # checking if the card is still valid
        if self.doc.xpath('//div[@id="errorbox"]'):
            return

        # adding a time delta because amex have hard time to put the date in a good interval
        beginning_date = self.get_beginning_debit_date() - datetime.timedelta(days=360)
        end_date = self.get_end_debit_date()

        guesser = ChaoticDateGuesser(beginning_date, end_date)

        # Since the site doesn't provide the debit_date,
        # we just use the date of beginning of the previous period.
        # If this date + 1 month is greater than today's date,
        # then the transaction is coming
        end_of_period = None
        previous_date = CleanText('//td[@id="colStatementBalance"]/div[3]', default=None)(self.doc)
        if previous_date:
            end_of_period = (parse_french_date(' '.join(previous_date.split()[1:4])) + relativedelta(months=1)).date()
        else:
            previous_date = CleanText('//select[@id="viewPeriod"]/option[@selected]', default=None)(self.doc)
            if previous_date:
                end_of_period = parse_french_date(' '.join(previous_date.split()[:3])) + relativedelta(days=-1) + relativedelta(months=1)
                end_of_period = end_of_period.date()

        _id = str(int(account._idforold))
        for tr in reversed(self.doc.xpath('//div[@id="txnsSection"]//tbody[@id="tableBody-txnsCard%s"]/tr[@class="tableStandardText"]' % _id)):
            cols = tr.findall('td')

            t = Transaction()

            day, month = CleanText().filter(cols[self.COL_DATE]).split(' ', 1)
            day = int(day)
            month = self.parse_month(month)
            date = guesser.guess_date(day, month)

            vdate = None
            try:
                detail = cols[self.COL_TEXT].xpath('./div[has-class("hiddenROC")]')[0]
            except IndexError:
                pass
            else:
                m = re.search(r' (\d{2} \D{3,4})', (' '.join([txt.strip() for txt in detail.itertext()])).strip())
                if m:
                    vday, vmonth = m.group(1).strip().split(' ')
                    vday = int(vday)
                    vmonth = self.parse_month(vmonth)
                    vdate = guesser.guess_date(vday, vmonth)
                detail.drop_tree()

            raw = (' '.join([txt.strip() for txt in cols[self.COL_TEXT].itertext()])).strip()
            credit = CleanText().filter(cols[self.COL_CREDIT])
            debit = CleanText().filter(cols[self.COL_DEBIT])
            if end_of_period is not None and datetime.date.today() < end_of_period:
                t._is_coming = True
            else:
                t._is_coming = False

            t.date = t.rdate = date
            t.vdate = vdate
            t.raw = re.sub(r'[ ]+', ' ', raw)
            t.label = re.sub('(.*?)( \d+)?  .*', r'\1', raw).strip()
            t.amount = parse_decimal(credit or debit) * (1 if credit else -1)
            if t.raw in self.browser.SUMMARY_CARD_LABEL:
                t.type = t.TYPE_CARD_SUMMARY
            elif t.amount > 0:
                t.type = t.TYPE_ORDER
            else:
                t.date = end_of_period
                t.type = t.TYPE_DEFERRED_CARD

            yield t
Esempio n. 2
0
    def get_history(self, currency):
        # checking if the card is still valid
        if self.doc.xpath('//div[@id="errorbox"]'):
            return

        # adding a time delta because amex have hard time to put the date in a good interval
        beginning_date = self.get_beginning_debit_date() - datetime.timedelta(
            days=360)
        end_date = self.get_end_debit_date()

        guesser = ChaoticDateGuesser(beginning_date, end_date)

        # Since the site doesn't provide the debit_date,
        # we just use the date of beginning of the previous period.
        # If this date + 1 month is greater than today's date,
        # then the transaction is coming
        end_of_period = None
        previous_date = CleanText('//td[@id="colStatementBalance"]/div[3]',
                                  default=None)(self.doc)
        if previous_date:
            end_of_period = (
                parse_french_date(' '.join(previous_date.split()[1:4])) +
                relativedelta(months=1)).date()
        else:
            previous_date = CleanText(
                '//select[@id="viewPeriod"]/option[@selected]',
                default=None)(self.doc)
            if previous_date:
                end_of_period = parse_french_date(' '.join(
                    previous_date.split()[:3])) + relativedelta(
                        days=-1) + relativedelta(months=1)
                end_of_period = end_of_period.date()

        for tr in reversed(
                self.doc.xpath(
                    '//div[@id="txnsSection"]//tbody/tr[@class="tableStandardText"]'
                )):
            cols = tr.findall('td')

            t = Transaction()

            day, month = CleanText().filter(cols[self.COL_DATE]).split(' ', 1)
            day = int(day)
            month = self.parse_month(month)
            date = guesser.guess_date(day, month)

            vdate = None
            try:
                detail = cols[self.COL_TEXT].xpath(
                    './div[has-class("hiddenROC")]')[0]
            except IndexError:
                pass
            else:
                m = re.search(r' (\d{2} \D{3,4})', (' '.join(
                    [txt.strip() for txt in detail.itertext()])).strip())
                if m:
                    vday, vmonth = m.group(1).strip().split(' ')
                    vday = int(vday)
                    vmonth = self.parse_month(vmonth)
                    vdate = guesser.guess_date(vday, vmonth)
                detail.drop_tree()

            raw = (' '.join([
                txt.strip() for txt in cols[self.COL_TEXT].itertext()
            ])).strip()
            credit = CleanText().filter(cols[self.COL_CREDIT])
            debit = CleanText().filter(cols[self.COL_DEBIT])
            if end_of_period is not None and datetime.date.today(
            ) < end_of_period:
                t._is_coming = True
            else:
                t._is_coming = False

            t.date = t.rdate = date
            t.vdate = vdate
            t.raw = re.sub(r'[ ]+', ' ', raw)
            t.label = re.sub('(.*?)( \d+)?  .*', r'\1', raw).strip()
            t.amount = parse_decimal(credit or debit) * (1 if credit else -1)
            if t.amount > 0:
                t.type = t.TYPE_ORDER
            else:
                t.date = end_of_period
                t.type = t.TYPE_DEFERRED_CARD

            yield t