X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/2903250a90904488ff3de04ecbbf2b6b5c421839..40b0da924b62ba147588a945718b71dc36ed3702:/lib/librarian/bin/book2txt.py diff --git a/lib/librarian/bin/book2txt.py b/lib/librarian/bin/book2txt.py index 86f6f1274..1ca4623fd 100755 --- a/lib/librarian/bin/book2txt.py +++ b/lib/librarian/bin/book2txt.py @@ -1,25 +1,8 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -import re import os import optparse -import codecs - -REGEXES = [ - (r']*>(.|\n)*?', ''), - (r']*>(.|\n)*?', ''), - ('<(begin|end)\\sid=[\'|"][b|e]\\d+[\'|"]\\s/>', ''), - (r'(()|())', ''), - (r'[^<]*', ''), - (r'(.|\n)*?

', ''), - (r'<[^>]+>', ''), - (r'/$', ''), - (r'---', u'—'), - (r'--', u'-'), - (r',,', u'„'), - (r'"', u'”'), -] +from librarian import text if __name__ == '__main__': @@ -44,13 +27,5 @@ if __name__ == '__main__': print input_filename output_filename = os.path.splitext(input_filename)[0] + '.txt' - - xml = codecs.open(input_filename, 'r', encoding='utf-8').read() - for pattern, repl in REGEXES: - # print pattern, repl - xml, n = re.subn(pattern, repl, xml) - # print n - - output = codecs.open(output_filename, 'w', encoding='utf-8') - output.write(xml) + text.transform(input_filename, output_filename)