Last active
August 29, 2015 14:01
-
-
Save powerswitch/87ff2fb65bd4501d32bc to your computer and use it in GitHub Desktop.
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
#!/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