[weboob] [PATCH 1/2] Added fuzzy option to Date/DateTime filters

Matthieu Weber mweber+weboob at free.fr
Tue Mar 22 19:47:41 CET 2016


Signed-off-by: Matthieu Weber <mweber+weboob at free.fr>
---
 weboob/browser/filters/standard.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/weboob/browser/filters/standard.py b/weboob/browser/filters/standard.py
index 3450e9f..cd9bb43 100644
--- a/weboob/browser/filters/standard.py
+++ b/weboob/browser/filters/standard.py
@@ -601,11 +601,13 @@ class Map(Filter):
 
 
 class DateTime(Filter):
-    def __init__(self, selector=None, default=_NO_DEFAULT, dayfirst=False, translations=None, parse_func=parse_date):
+    def __init__(self, selector=None, default=_NO_DEFAULT, dayfirst=False, translations=None,
+                 parse_func=parse_date, fuzzy=False):
         super(DateTime, self).__init__(selector, default=default)
         self.dayfirst = dayfirst
         self.translations = translations
         self.parse_func = parse_func
+        self.fuzzy = fuzzy
 
     @debug()
     def filter(self, txt):
@@ -615,14 +617,16 @@ class DateTime(Filter):
             if self.translations:
                 for search, repl in self.translations:
                     txt = search.sub(repl, txt)
-            return self.parse_func(txt, dayfirst=self.dayfirst)
+            return self.parse_func(txt, dayfirst=self.dayfirst, fuzzy=self.fuzzy)
         except (ValueError, TypeError) as e:
             return self.default_or_raise(ParseError('Unable to parse %r: %s' % (txt, e)))
 
 
 class Date(DateTime):
-    def __init__(self, selector=None, default=_NO_DEFAULT, dayfirst=False, translations=None, parse_func=parse_date):
-        super(Date, self).__init__(selector, default=default, dayfirst=dayfirst, translations=translations, parse_func=parse_func)
+    def __init__(self, selector=None, default=_NO_DEFAULT, dayfirst=False, translations=None,
+                 parse_func=parse_date, fuzzy=False):
+        super(Date, self).__init__(selector, default=default, dayfirst=dayfirst, translations=translations,
+                                   parse_func=parse_func, fuzzy=fuzzy)
 
     @debug()
     def filter(self, txt):
-- 
2.1.4




More information about the weboob mailing list