1. Jesse London
  2. dropbox

Commits

Jesse London  committed 375c228 Draft

rtf-to-text tweaks

  • Participants
  • Parent commits 8d514a1
  • Branches default

Comments (0)

Files changed (1)

File parser/convertrtf.py

View file
 from __future__ import print_function
+import glob
+import os.path
+import re
+import sys
 import tempfile
+from itertools import chain
 from xml.dom import minidom
 
 import rtf2xml.ParseRtf
         yield extract_text(para)
 
 
-def main(path):
-    print(*stream(path), sep='\n')
+def main(path, fh=sys.stdout):
+    print(*stream(path), sep='\n', file=fh)
 
 
 if __name__ == '__main__':
-    import sys
-    main(sys.argv[1])
+    for path in chain.from_iterable(glob.glob(arg) for arg in sys.argv[1:]):
+        txt_name = re.sub(r'\.rtf$', '.txt', path)
+        if not txt_name.endswith('.txt'):
+            continue
+        if os.path.exists(txt_name):
+            raise RuntimeError("Path {0} already exists".format(txt_name))
+        main(path, open(txt_name, 'w'))