diff options
| -rw-r--r-- | scripts/mammoth | 42 | ||||
| -rw-r--r-- | setup.py | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/scripts/mammoth b/scripts/mammoth new file mode 100644 index 0000000..4de4120 --- /dev/null +++ b/scripts/mammoth @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +import argparse +import contextlib +import sys + +import mammoth + + +def main(): + args = _parse_args() + + with _open_output(args.output) as output: + with open(args.path, "rb") as docx_fileobj: + result = mammoth.convert_to_html(docx_fileobj) + for message in result.messages: + sys.stderr.write(message.message) + sys.stderr.write("\n") + output.write(result.value) + + +@contextlib.contextmanager +def _open_output(name): + if name is None: + try: + yield sys.stdout + finally: + sys.stdout.flush() + else: + with open(name, "w") as output: + yield output + + +def _parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("path") + parser.add_argument("output", nargs="?") + return parser.parse_args() + + +if __name__ == "__main__": + main() @@ -15,6 +15,7 @@ setup( author_email='mike@zwobble.org', url='http://github.com/mwilliamson/python-mammoth', packages=['mammoth', 'mammoth.docx', 'mammoth.style_reader'], + scripts=["scripts/mammoth"], keywords="docx word office clean html", install_requires=[ "parsimonious>=0.5,<0.6", |
