Skip to content

Instantly share code, notes, and snippets.

@zooid
Forked from JGVerdugo/ziptest.py
Created August 13, 2018 01:51
Show Gist options
  • Save zooid/79df4ccaccd121eb202d9b54d54a10f2 to your computer and use it in GitHub Desktop.
Save zooid/79df4ccaccd121eb202d9b54d54a10f2 to your computer and use it in GitHub Desktop.
Learning to use Python zipfile module with docx files
#!/usr/bin/python
import os
import os.path
import zipfile
from datetime import datetime
from re import sub
sourceFile = zipfile.ZipFile('text.docx')
list = sourceFile.namelist()
publicDir = os.getenv("TMP")
timestamp = datetime.now().isoformat()
timestamp = sub("[:.]", "", timestamp)
dirname = "xtemp-jgv-" + timestamp
tempDir = os.path.join(publicDir, dirname)
os.mkdir(tempDir)
sourceFile.extractall(tempDir)
documentPath = os.path.join(tempDir, "word")
document = open(os.path.join(documentPath, "document.xml"), "a+")
document.seek(2666)
print document.read(466)
print document.tell()
sourceFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment