2 # -*- coding: utf-8 -*-
10 (r'<rdf:RDF[^>]*>(.|\n)*?</rdf:RDF>', ''),
11 (r'<motyw[^>]*>(.|\n)*?</motyw>', ''),
12 ('<(begin|end)\\sid=[\'|"][b|e]\\d+[\'|"]\\s/>', ''),
13 (r'<extra>((<!--<(elementy_poczatkowe|tekst_glowny)>-->)|(<!--</(elementy_poczatkowe|tekst_glowny)>-->))</extra>', ''),
14 (r'<uwaga>(.|\n)*?</uwaga>', ''),
15 (r'<p[a|e|r|t]>(.|\n)*?</p[a|e|r|t]>', ''),
25 if __name__ == '__main__':
26 # Parse commandline arguments
27 usage = """Usage: %prog [options] SOURCE [SOURCE...]
28 Convert SOURCE files to TXT format."""
30 parser = optparse.OptionParser(usage=usage)
32 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
33 help='print status messages to stdout')
35 options, input_filenames = parser.parse_args()
37 if len(input_filenames) < 1:
42 for input_filename in input_filenames:
46 output_filename = os.path.splitext(input_filename)[0] + '.txt'
48 xml = codecs.open(input_filename, 'r', encoding='utf-8').read()
49 for pattern, repl in REGEXES:
51 xml, n = re.subn(pattern, repl, xml)
54 output = codecs.open(output_filename, 'w', encoding='utf-8')