X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/43b0d0350b82618ba9e46a8f71090211a596a1af..5adcf1231e8d4a4131bd09798f4dd296bd430081:/lib/librarian/bin/book2txt.py?ds=inline diff --git a/lib/librarian/bin/book2txt.py b/lib/librarian/bin/book2txt.py index 84a8f4084..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', '\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)