-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_multiple.py
35 lines (27 loc) · 1.01 KB
/
convert_multiple.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
from weasyprint import HTML, default_url_fetcher
from weasyprint.fonts import FontConfiguration
from datetime import date
import yaml
import os
import ssl
import logging
def fetcher_timout(url, timeout=3600):
return default_url_fetcher(url, timeout)
LOG_DIR = "/app/logs/"
DEST_DIR = "/app/output/"
CONFIG_DIR = "/app/config/"
logger = logging.getLogger('weasyprint')
logger.setLevel(level=os.environ.get("LOGLEVEL", "INFO").upper())
logger.addHandler(logging.FileHandler(LOG_DIR + 'weasyprint.log'))
ssl._create_default_https_context = ssl._create_unverified_context
now = date.today()
date = now.strftime("%Y%m%d")
font_config = FontConfiguration()
config_file = CONFIG_DIR + "config.yml"
with open(config_file) as file:
config = yaml.load(file, Loader=yaml.FullLoader)
for name, html in config['html_files'].items():
dest = DEST_DIR + name
dest = dest.replace("{{DATE}}", date)
logger.debug("Generate " + html + " into " + dest)
HTML(html, url_fetcher=fetcher_timout).write_pdf(dest, font_config=font_config)