-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatePDF.py
38 lines (32 loc) · 944 Bytes
/
updatePDF.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
import os
import shutil
from subprocess import call
from os import path
from zipfile import *
every_file = os.listdir()
def is_selected(fn):
suff = ['.doc', '.docx', '.ppt', '.pptx']
_, ext = path.splitext(fn)
return ext in suff
def new_filename(fn):
base, _ = path.splitext(fn)
return path.extsep.join((base, 'pdf'))
def convert(fn):
new_fn = new_filename(fn)
call(['cli2pdf', fn])
# ask for rewrite
os.system('copy /-y "%s" pdf' % new_fn)
return new_fn
def is_outdated(fn):
new_fn = path.join('pdf', new_filename(fn))
return not path.exists(new_fn) or path.getmtime(fn) > path.getctime(new_fn)
lst = [i for i in every_file if is_selected(i) and is_outdated(i)]
if lst:
zf = ZipFile('pdf\\newest.zip', 'w')
for i in lst:
new_fn = convert(i)
zf.write(new_fn)
os.remove(new_fn)
zf.close()
else:
print('Updated.')