Last active
August 29, 2015 14:17
-
-
Save tlinkner/b8918a49ae75f2dd099b to your computer and use it in GitHub Desktop.
Word Doc to Clean HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # Setup: install pandoc | |
| # https://github.com/jgm/pandoc/releases | |
| # To run script: | |
| # python python docx2html.py [filepath] | |
| # Platypus app setup: | |
| # App Name: docx2html | |
| # Script Type: Python | |
| # Path: /usr/bin/python | |
| # Script Path: Edit: [Paste In] | |
| # Args: none | |
| # Output: Progress Bar | |
| # Accpets Dropped Items: True | |
| # Remain Running After Initial Execution: True | |
| import string | |
| import sys | |
| import os | |
| import subprocess | |
| print "This app will make clean HTML from a DOCX file." | |
| if os.path.exists('/usr/local/bin/pandoc'): | |
| # System has pandoc | |
| if len(sys.argv) > 1: | |
| filepath = sys.argv[1] | |
| if os.path.isfile(filepath): | |
| filename, filesuffix = os.path.splitext(filepath) | |
| if filesuffix == ".docx": | |
| htmlfile = string.replace(filename + ".html", " ", "-") | |
| subprocess.call(['/usr/local/bin/pandoc -s "' + filepath + '" -t markdown | /usr/local/bin/pandoc -t html -o ' + htmlfile], shell=True) | |
| print "File processed: " + htmlfile | |
| else: | |
| print "Wrong file type. Please supply a .DOCX file." | |
| else: | |
| print "File path is invalid. Please supply a valid file path." | |
| else: | |
| print "Please supply file path as an argument." | |
| else: | |
| # Need to install pandoc | |
| print "This script requires pandoc. Please install it from https://github.com/jgm/pandoc/releases" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment