-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverpage-folder-processor.py
executable file
·38 lines (32 loc) · 1.26 KB
/
coverpage-folder-processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import funcs
import sys
import os
import shutil
import subprocess
folder = sys.argv[1]
if not os.path.exists(folder):
sys.exit('{} does not exist.'.format(folder))
if not os.path.isdir(folder):
sys.exit('{} is not a folder.'.format(folder))
procfolder = '{}_processed'.format(folder)
if os.path.exists(procfolder):
shutil.rmtree(procfolder)
os.makedirs(procfolder)
counts = {'total': 0, 'uncovered': 0, 'decovered': 0}
for file in os.listdir(folder):
counts['total'] += 1
print('')
if file.endswith('.pdf'):
if not funcs.has_fsul_coverpage('{}/{}'.format(folder, file)):
counts['uncovered'] += 1
print('{} does not have an FSUL coverpage.'.format(file))
else:
counts['decovered'] += 1
print('{} has an FSUL coverpage.'.format(file))
subprocess.run(['pdftk', '{}/{}'.format(folder, file), 'cat', '2-end', 'output', '{}/{}'.format(procfolder, file)])
print('{} has has been copied to {} without coverpage.'.format(file, procfolder))
print('')
print('Total PDFs in {}: {}'.format(folder, counts['total']))
print('Total PDFs skipped due to lack of FSUL coverpage: {}'.format(counts['uncovered']))
print('Total PDFs processed into {} to remove FSUL coverpage: {}'.format(procfolder, counts['decovered']))