fixing date not in the good interval
This commit is contained in:
parent
9855ae8fa9
commit
64ef0de61d
3 changed files with 20 additions and 21 deletions
|
|
@ -62,10 +62,5 @@ class AmericanExpressBackend(BaseBackend, ICapBank):
|
||||||
with self.browser:
|
with self.browser:
|
||||||
transactions = list(self.browser.get_history(account))
|
transactions = list(self.browser.get_history(account))
|
||||||
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
||||||
return [tr for tr in transactions if not tr._is_coming]
|
return transactions
|
||||||
|
|
||||||
def iter_coming(self, account):
|
|
||||||
with self.browser:
|
|
||||||
transactions = list(self.browser.get_history(account))
|
|
||||||
transactions.sort(key=lambda tr: tr.rdate, reverse=True)
|
|
||||||
return [tr for tr in transactions if tr._is_coming]
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
from urlparse import urlsplit, parse_qsl
|
from urlparse import urlsplit, parse_qsl
|
||||||
|
|
||||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
||||||
from weboob.tools.date import LinearDateGuesser
|
from weboob.tools.date import ChaoticDateGuesser
|
||||||
|
|
||||||
from .pages import LoginPage, AccountsPage, TransactionsPage
|
from .pages import LoginPage, AccountsPage, TransactionsPage
|
||||||
|
|
||||||
|
|
@ -85,9 +85,6 @@ class AmericanExpressBrowser(BaseBrowser):
|
||||||
|
|
||||||
url = account._link
|
url = account._link
|
||||||
|
|
||||||
coming = True
|
|
||||||
date_guesser = LinearDateGuesser()
|
|
||||||
|
|
||||||
while url is not None:
|
while url is not None:
|
||||||
self.select_form(name='leftnav')
|
self.select_form(name='leftnav')
|
||||||
self.form.action = self.absurl(url)
|
self.form.action = self.absurl(url)
|
||||||
|
|
@ -95,10 +92,7 @@ class AmericanExpressBrowser(BaseBrowser):
|
||||||
|
|
||||||
assert self.is_on_page(TransactionsPage)
|
assert self.is_on_page(TransactionsPage)
|
||||||
|
|
||||||
for tr in self.page.get_history(date_guesser):
|
for tr in self.page.get_history():
|
||||||
if tr.amount > 0:
|
|
||||||
coming = False
|
|
||||||
tr._is_coming = coming
|
|
||||||
yield tr
|
yield tr
|
||||||
|
|
||||||
if self.page.is_last():
|
if self.page.is_last():
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ from weboob.tools.browser import BasePage, BrokenPageError
|
||||||
from weboob.capabilities.bank import Account
|
from weboob.capabilities.bank import Account
|
||||||
from weboob.capabilities import NotAvailable
|
from weboob.capabilities import NotAvailable
|
||||||
from weboob.tools.capabilities.bank.transactions import FrenchTransaction as Transaction
|
from weboob.tools.capabilities.bank.transactions import FrenchTransaction as Transaction
|
||||||
|
from weboob.tools.date import ChaoticDateGuesser
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['LoginPage', 'AccountsPage', 'TransactionsPage']
|
__all__ = ['LoginPage', 'AccountsPage', 'TransactionsPage']
|
||||||
|
|
@ -78,10 +79,18 @@ class TransactionsPage(BasePage):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_debit_date(self):
|
def get_end_debit_date(self):
|
||||||
for option in self.document.xpath('//select[@id="viewPeriod"]/option'):
|
for option in self.document.xpath('//select[@id="viewPeriod"]/option'):
|
||||||
if 'selected' in option.attrib:
|
if 'selected' in option.attrib:
|
||||||
m = re.search('(\d+) ([\w\.]+) (\d{4})$', option.text.strip())
|
m = re.search('(\d+) ([\w\.]+) (\d{4})$', option.text.strip(), re.UNICODE)
|
||||||
|
if m:
|
||||||
|
return datetime.date(int(m.group(3)),
|
||||||
|
self.MONTHS.index(m.group(2).rstrip('.')) + 1,
|
||||||
|
int(m.group(1)))
|
||||||
|
def get_beginning_debit_date(self):
|
||||||
|
for option in self.document.xpath('//select[@id="viewPeriod"]/option'):
|
||||||
|
if 'selected' in option.attrib:
|
||||||
|
m = re.search('^(\d+) ([\w\.]+) (\d{4})', option.text.strip(), re.UNICODE)
|
||||||
if m:
|
if m:
|
||||||
return datetime.date(int(m.group(3)),
|
return datetime.date(int(m.group(3)),
|
||||||
self.MONTHS.index(m.group(2).rstrip('.')) + 1,
|
self.MONTHS.index(m.group(2).rstrip('.')) + 1,
|
||||||
|
|
@ -94,10 +103,11 @@ class TransactionsPage(BasePage):
|
||||||
|
|
||||||
MONTHS = ['janv', u'févr', u'mars', u'avr', u'mai', u'juin', u'juil', u'août', u'sept', u'oct', u'nov', u'déc']
|
MONTHS = ['janv', u'févr', u'mars', u'avr', u'mai', u'juin', u'juil', u'août', u'sept', u'oct', u'nov', u'déc']
|
||||||
|
|
||||||
def get_history(self, guesser):
|
def get_history(self):
|
||||||
debit_date = self.get_debit_date()
|
#adding a time delta because amex have hard time to put the date in a good interval
|
||||||
if debit_date is not None:
|
beginning_date = self.get_beginning_debit_date() - datetime.timedelta(days=30)
|
||||||
guesser.current_date = debit_date
|
end_date = self.get_end_debit_date()
|
||||||
|
guesser = ChaoticDateGuesser(beginning_date, end_date)
|
||||||
|
|
||||||
for tr in reversed(self.document.xpath('//div[@id="txnsSection"]//tr[@class="tableStandardText"]')):
|
for tr in reversed(self.document.xpath('//div[@id="txnsSection"]//tr[@class="tableStandardText"]')):
|
||||||
cols = tr.findall('td')
|
cols = tr.findall('td')
|
||||||
|
|
@ -107,7 +117,7 @@ class TransactionsPage(BasePage):
|
||||||
day, month = self.parser.tocleanstring(cols[self.COL_DATE]).split(' ', 1)
|
day, month = self.parser.tocleanstring(cols[self.COL_DATE]).split(' ', 1)
|
||||||
day = int(day)
|
day = int(day)
|
||||||
month = self.MONTHS.index(month.rstrip('.')) + 1
|
month = self.MONTHS.index(month.rstrip('.')) + 1
|
||||||
date = guesser.guess_date(day, month, False)
|
date = guesser.guess_date(day, month)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
detail = self.parser.select(cols[self.COL_TEXT], 'div.hiddenROC', 1)
|
detail = self.parser.select(cols[self.COL_TEXT], 'div.hiddenROC', 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue