forked from jackzhenguo/python-small-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.py
More file actions
30 lines (24 loc) · 768 Bytes
/
convert.py
File metadata and controls
30 lines (24 loc) · 768 Bytes
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
import cloudconvert
import os
import time
api = cloudconvert.Api(
'NrtpV6kD5BdVxJ2R20eBqgCHK6heTjEMxtWSWENeZ9HdKUj5Ew3aCpodMCPPwLeH')
def convert(input_file):
filename, ext = os.path.splitext(input_file)
if ext != '.md':
return
print(f'begin to convert {filename}...')
process = api.convert({
'inputformat': 'md',
'outputformat': 'pdf',
'input': 'upload',
'file': open('./{}'.format(input_file), 'rb')
})
process.wait() # wait until conversion finished
# download output file
process.download(
"./tmp/{}.pdf".format(filename))
print(f"convert {filename} success")
for input_file in os.listdir('.'):
convert(input_file)
# time.sleep(1)