From c023e15be620717339a780b6f4960649a9952afe Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 1 Nov 2013 01:41:34 +0100 Subject: HTML-XSLT import: parse dates of events --- chimere/utils.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'chimere/utils.py') diff --git a/chimere/utils.py b/chimere/utils.py index 8c8624e..1985f89 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -845,6 +845,35 @@ RE_CLEANS = ((re.compile('(\n)*|^( )*(\n)*( )*|( )*(\n)*( )*$'), ''), '\d{1,2}) '\ + r'(?P'+ '|'.join(UNI_MONTH_NAMES['fr_FR']) +') '\ + r'(?P\d{4})?[^\d]*'\ + r'(?P\d{1,2}) '\ + r'(?P'+ '|'.join(UNI_MONTH_NAMES['fr_FR']) +') *'\ + r'(?P\d{4})?.*'), + re.compile(r'(?P\d{1,2}) '\ + r'(?P'+ '|'.join(UNI_MONTH_NAMES['fr_FR']) +') *'\ + r'(?P\d{4})?') + ] + } + + class HtmlXsltManager(ImportManager): def get(self): u""" @@ -942,7 +971,32 @@ class HtmlXsltManager(ImportManager): else: dct['point'] = self.importer_instance.default_localisation dct['description'] = item['description'] + if 'date' in item: + has_dates = False + for locale in DATE_PARSINGS: + if has_dates: + break + for r in DATE_PARSINGS[locale]: + m = r.search(item['date']) + if not m: + continue + has_dates = True + values = m.groupdict() + year1 = datetime.date.today().year if 'year1' not in values \ + else int(values['year1']) + dct['start_date'] = datetime.date(year1, + MONTH_NAMES[locale].index(values['month1'].encode('utf-8')) + 1, + int(values['day1'])) + if 'day2' not in values: + break + year2 = datetime.date.today().year if 'year2' not in values \ + else int(values['year2']) + dct['end_date'] = datetime.date(year2, + MONTH_NAMES[locale].index(values['month2'].encode('utf-8')) + 1, + int(values['day2'])) + break key = item['key'] + print dct it, updated, created = self.create_or_update_item(cls, dct, key) if updated: updated_item += 1 -- cgit v1.2.3