Skip to content

Instantly share code, notes, and snippets.

@tlinkner
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save tlinkner/b8918a49ae75f2dd099b to your computer and use it in GitHub Desktop.

Select an option

Save tlinkner/b8918a49ae75f2dd099b to your computer and use it in GitHub Desktop.
Word Doc to Clean HTML
#!/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