Skip to content

Instantly share code, notes, and snippets.

@malexandre
Created July 2, 2015 14:29
Show Gist options
  • Save malexandre/b29f26b9912c82230ee6 to your computer and use it in GitHub Desktop.
Save malexandre/b29f26b9912c82230ee6 to your computer and use it in GitHub Desktop.
Copy the content of a docx inside another in python app engine
from server.api.drive import Drive
from server.libs.docx import Document
from cStringIO import StringIO
driveFile = Drive.getFile('DRIVE_ID')
doc = Document(StringIO(Drive.downloadFile(driveFile['downloadUrl'])))
doc_to_copy = Document(StringIO(Drive.downloadFile(Drive.getFile('DRIVE_ID_TO_COPY')['downloadUrl'])))
for element in doc_to_copy._body._element:
doc._body._element.append(element)
output = StringIO()
doc.save(output)
Drive.uploadFile('test-result.docx',
driveFile.get('mimeType'),
output,
None,
False,
'owner.email@google.com')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment