Created
April 5, 2016 17:47
-
-
Save copyleftdev/ee8edb61a4aba40ce2fc653e12cd5e69 to your computer and use it in GitHub Desktop.
convert wiki from text format to docx
This file contains 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
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) | |
for each_file in flst: | |
#each_file.encode('utf-8') | |
with open(each_file, 'r') as rdcontent: | |
xdoc = Document() | |
xdoc.add_paragraph('{}'.format(rdcontent.readlines())) | |
xdoc.save('{}/{}.docx'.format(os.path.dirname(os.path.realpath(each_file)),uuid.uuid4())) | |
print ("{} converted to docx".format(each_file)) | |
convertToDocx('data/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment