Last active
August 29, 2015 14:27
-
-
Save tdussa/1f1af48b04a4d5d16fb9 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/env python | |
import fileinput | |
def shipout(aerodrome, count, pdfstring): | |
file = open(aerodrome + '_' + str(count) + '.pdf', 'w') | |
file.write(pdfstring) | |
count = 0 | |
aerodrome = '' | |
pdfstring = '' | |
tempstring = '' | |
for line in fileinput.input(): | |
index = line.find('%PDF-1.') | |
if index != -1: | |
if count > 0: | |
print(aerodrome + ' ' + str(count) + ' end settled.\n') | |
shipout(aerodrome, count, pdfstring) | |
pdfstring = '' | |
if not line[2:index] == aerodrome: | |
count = 0 | |
count += 1 | |
aerodrome = line[2:index] | |
pdfstring = line[index:] | |
tempstring = '' | |
print(aerodrome + ' ' + str(count) + ' begin detected.') | |
else: | |
if line.find('%%EOF') >= 0: | |
tempstring += line | |
pdfstring += tempstring | |
tempstring = '' | |
print(' Possible end of ' + aerodrome + ' ' + str(count) + ' detected') | |
else: | |
tempstring += line | |
print(aerodrome + ' ' + str(count) + ' end settled.\n') | |
shipout(aerodrome, count, pdfstring) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment