[weboob] [PATCH 1/1] CRAGR: Fix wrong dates on day and month

Richard Genoud richard.genoud at gmail.com
Thu Oct 25 20:24:27 CEST 2012


The regex to match the transaction date DD/MM was:
([012]?[0-9]|3[01])\s*/\s*(0?[1-9]|1[012])
So a date like 31/10 was match as (3)1/(1) => 03/01
Because python stops as soon as there a match in a group, in this case
[012]?[0-9]\s*/\s*0?[1-9] matches.
(at least, I verified it for the month part).
A simple way to get the regex right is to match the non facultative
parts (?) first:
(3[01]|[012]?[0-9])\s*/\s*(1[012]|0?[1-9])

tested on CA-centre-france with date in october (01/10 - 10/10 - 23/10)

Signed-off-by: Richard Genoud <richard.genoud at gmail.com>
---
 modules/cragr/pages/accounts_list.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/cragr/pages/accounts_list.py b/modules/cragr/pages/accounts_list.py
index 53238d7..82b5d58 100644
--- a/modules/cragr/pages/accounts_list.py
+++ b/modules/cragr/pages/accounts_list.py
@@ -217,7 +217,7 @@ class AccountsList(CragrBasePage):
         """
             Builds a date object from a 'DD/MM' string
         """
-        matches = re.search('([012]?[0-9]|3[01])\s*/\s*(0?[1-9]|1[012])', string)
+        matches = re.search('(3[01]|[012]?[0-9])\s*/\s*(1[012]|0?[1-9])', string)
         if matches is None:
             return self.fallback_date()
         return self.date_from_day_month(int(matches.group(1)), int(matches.group(2)))
-- 
1.7.10.4




More information about the weboob mailing list