-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-script.py
More file actions
65 lines (55 loc) · 1.39 KB
/
Copy pathpython-script.py
File metadata and controls
65 lines (55 loc) · 1.39 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pdfkit
import sys
import json
try:
input = sys.argv[1]
except IOError as error:
print(error)
print("Missing input file")
sys.exit()
try:
output = sys.argv[2]
except IOError as error:
print(error)
print("Output path undefined")
sys.exit()
try:
type = sys.argv[3]
except IOError as error:
print(error)
sys.exit()
try:
options = sys.argv[4]
except IOError as error:
print(error)
sys.exit()
class Path:
def __init__(self, input, output, setting):
self._i = input
self._o = output
self._opt = setting
def from_file(self):
try:
if (self._opt != "false"):
self._opt = json.loads(self._opt)
pdfkit.from_file(self._i, self._o, options=self._opt)
else:
pdfkit.from_file(self._i, self._o)
except IOError as error:
print(error)
def from_url(self):
try:
if (self._opt != "false"):
self._opt = json.loads(self._opt)
pdfkit.from_url(self._i, self._o, options=self._opt)
else:
pdfkit.from_url(self._i, self._o)
except IOError as error:
print(error)
def main():
render = Path(input, output, options)
if type == "true":
render.from_file()
else:
render.from_url()
if __name__ == "__main__": main()