X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/f8228cc6712f9a71f877b0ea60719c256519f16e..40b0da924b62ba147588a945718b71dc36ed3702:/lib/librarian/bin/book2txt.py?ds=sidebyside diff --git a/lib/librarian/bin/book2txt.py b/lib/librarian/bin/book2txt.py index 413ff674b..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'(.|\n)*?', ''), - (r'(.|\n)*?', ''), - (r'<[^>]+>', ''), - (r'/\n', ''), - (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)