-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerator_script.py
44 lines (37 loc) · 1.2 KB
/
generator_script.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
39
40
41
42
43
44
import sys
import json
import tempfile
from generator import PdfGenerator
def from_json_file(filepath):
"""
Read the generated JSON file and instantiate a PdfGenerator with the properties.
Parameters:
- filepath: The path to the JSON file.
Returns:
- An instance of PdfGenerator with the properties from the JSON file.
"""
with open(filepath, "r") as file:
data = json.load(file)
reuslt = PdfGenerator(
main_html=data["main_html"],
header_html=data["header_html"],
footer_html=data["footer_html"],
last_footer_html=data["last_footer_html"],
base_url=data["base_url"],
side_margin=data["side_margin"],
extra_vertical_margin=data["extra_vertical_margin"]
)
return reuslt
def main(argv):
json_filepath = argv[1]
pdf_generator = from_json_file(json_filepath)
result = pdf_generator.render_html().write_pdf()
with tempfile.NamedTemporaryFile(delete=False) as temp:
temp.write(result)
return temp.name
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Debe proporcionar la ruta del archivo JSON como argumento.")
sys.exit(1)
print(main(sys.argv))
sys.exit(0)