This paste expires on 2023-05-23 12:46:30.099941. Repaste, or download this paste. . Pasted through web.

#!/usr/bin/env python3
import os
import sys
import zipfile
from os.path import basename, dirname, join
PATTERN_1 = '<table:table '
PATTERN_2 = '</table:table>'
if len(sys.argv) < 2:
print("Usage: %s <file.odt>" % sys.argv[0])
sys.exit()
tmpdir = '/tmp'
src = sys.argv[1]
dst = src.replace('.odt', '_anon.odt')
extract_dir = join(tmpdir, 'ooextract')
zipdata = zipfile.ZipFile(src)
zipdata.extractall(extract_dir)
content = join(extract_dir, 'content.xml')
with open(content) as fd:
xml = fd.read()
index1 = xml.find(PATTERN_1)
index2 = xml.find(PATTERN_2)
if index1 < 0 or index2 < 0:
print("No table found! Quitting.")
sys.exit()
newxml = xml[0:index1] + xml[index2 + len(PATTERN_2):]
with open(content, 'w') as fd:
fd.write(newxml)
with zipfile.ZipFile(dst, 'w') as fd:
    zipinfos = zipdata.infolist()
    for zipinfo in zipinfos:
        filename = zipinfo.filename
        filepath = join(extract_dir, filename)
        fd.write(filepath, filename)
import shutil
shutil.rmtree(extract_dir)
Filename: None. Size: 1kb. View raw, , hex, or download this file.