Skip to content

Instantly share code, notes, and snippets.

@copyleftdev
Created April 1, 2016 02:32
Show Gist options
  • Save copyleftdev/0b42384220a55c34d0ccd1c5107ec9c1 to your computer and use it in GitHub Desktop.
Save copyleftdev/0b42384220a55c34d0ccd1c5107ec9c1 to your computer and use it in GitHub Desktop.
wikitodocx
import os
from docx import Document
import uuid
def getDocList(rootFoldr):
filelst = []
for(dirpath, _, files) in os.walk(rootFoldr):
for filename in files:
filepath = os.path.join(dirpath, filename)
filelst.append(filepath)
return (filelst)
def convertToDocx(rootFoldr):
flst = getDocList(rootFoldr)
xdoc = Document()
for each_file in flst:
with open(each_file, 'r') as rdcontent:
for every_line in rdcontent.readlines():
print every_line
print "NEW BREAK"
#xdoc.add_paragraph('{}'.format(str(each_line)))
#xdoc.save('{}/{}.docx'.format(os.path.dirname(os.path.realpath(each_file)),uuid.uuid4()))
convertToDocx('data/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment