Skip to content

Instantly share code, notes, and snippets.

@powerswitch
Last active August 29, 2015 14:01
Show Gist options
  • Save powerswitch/87ff2fb65bd4501d32bc to your computer and use it in GitHub Desktop.
Save powerswitch/87ff2fb65bd4501d32bc to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# merge two xournal/cournal files of same document
import gzip
import sys
if len(sys.argv) != 4:
print("usage: mergexoj.py FILE1 FILE2 OUTPUT")
exit()
FILE1 = sys.argv[1]
FILE2 = sys.argv[2]
OUTPUT = sys.argv[3]
page = 0
content = []
temp = ""
header = ""
switch = False
f = gzip.GzipFile(FILE1, "rb")
for line in f:
if line[:5] == "<page":
switch = True
elif line[:6] == "</page":
page += 1
content.append(temp)
temp = ""
elif line[:11] == "<background":
pass
else:
if switch == False:
header += line
else:
temp += line
f.close()
f = gzip.GzipFile(FILE2, "rb")
o = gzip.GzipFile(OUTPUT, "wb")
for line in f:
if line[:6] == "</page":
if len(content) > 0:
o.write(content.pop(0))
o.write(line)
else:
o.write(line)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment