wcs-dynexport : intégration du basculement vers PostgreSQL (suite)
[progfou.git] / outils / ooo-text2date
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 import sys
4 import re
5
6 PAT1 = 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>'
7 PAT2 = 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
9 def 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
15 pattern = re.compile(PAT1, re.MULTILINE)
16 sys.stdout.write(re.sub(pattern, text2date, sys.stdin.read()))