list2form : gestion des erreurs et des petits fichiers (merci cgi.py…)
[progfou.git] / outils / ooo-text2date
... / ...
CommitLineData
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3import sys
4import re
5
6PAT1 = r'<table:table-cell (?P<attrs>[^>]*)office:value-type="string">(?P<s1>\s*)<text:p>(?P<day>[0-9][0-9])/(?P<month>[0-9][0-9])/(?P<year>[0-9][0-9])</text:p>(?P<s2>\s*)</table:table-cell>'
7PAT2 = r'<table:table-cell \g<attrs>office:value-type="date" office:date-value="%(year)s-\g<month>-\g<day>">\g<s1><text:p>\g<day>/\g<month>/\g<year></text:p>\g<s2></table:table-cell>'
8
9def text2date(matchobj):
10 year = int(matchobj.group('year'))
11 if year < 100: year += 1900
12 if year < 1930: year += 100
13 return matchobj.expand(PAT2) % {'year': year}
14
15pattern = re.compile(PAT1, re.MULTILINE)
16sys.stdout.write(re.sub(pattern, text2date, sys.stdin.read()))