adding ChaoticDateGuesser when you know an interval

This commit is contained in:
Vincent Paredes 2014-02-24 19:02:38 +01:00 committed by Romain Bignon
commit 158efcded0
2 changed files with 21 additions and 1 deletions

View file

@ -21,7 +21,6 @@
from urlparse import urlsplit, parse_qsl
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
from weboob.tools.date import ChaoticDateGuesser
from .pages import LoginPage, AccountsPage, TransactionsPage

View file

@ -201,6 +201,27 @@ class LinearDateGuesser(object):
self.set_current_date(parsed_date)
return parsed_date
class ChaoticDateGuesser(LinearDateGuesser):
"""
This class aim to find the guess the date when you know the
day and month and the minimum year
"""
def __init__(self, min_date, current_date=None, date_max_bump=timedelta(7)):
if min_date is None:
raise ValueError("min_date is not set")
self.min_date = min_date
super(ChaoticDateGuesser, self).__init__(current_date, date_max_bump)
def guess_date(self, day, month):
"""Returns a possible date between min_date and current_date"""
parsed_date = super(ChaoticDateGuesser, self).guess_date(day, month, False)
if parsed_date >= self.min_date:
return parsed_date
else:
raise ValueError("%s is inferior to min_date %s" % (parsed_date, self.min_date))
DATE_TRANSLATE_FR = [(re.compile(u'janvier', re.I), u'january'),
(re.compile(u'février', re.I), u'february'),
(re.compile(u'mars', re.I), u'march'),