Extracted from project "Wolnelektury.pl". Version 1.1
[librarian.git] / scripts / book2txt
1 #!/usr/bin/env python
2 import os
3 import optparse
4
5 from librarian import text
6
7
8 if __name__ == '__main__':
9     # Parse commandline arguments
10     usage = """Usage: %prog [options] SOURCE [SOURCE...]
11     Convert SOURCE files to TXT format."""
12
13     parser = optparse.OptionParser(usage=usage)
14
15     parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
16         help='print status messages to stdout')
17
18     options, input_filenames = parser.parse_args()
19
20     if len(input_filenames) < 1:
21         parser.print_help()
22         exit(1)
23
24     # Do some real work
25     for input_filename in input_filenames:
26         if options.verbose:
27             print input_filename
28         
29         output_filename = os.path.splitext(input_filename)[0] + '.txt'
30         text.transform(input_filename, output_filename)
31