forked from mattvenn/printable-diary
/
cover.py
executable file
·31 lines (24 loc) · 965 Bytes
/
cover.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import svglue
import cairosvg
parser = argparse.ArgumentParser(description="read meter, post to internet and send to energy wristband")
parser.add_argument('--text', action='store',
help="text")
parser.add_argument('--image', action='store',
help="image")
args = parser.parse_args()
# load the template from a file
tpl = svglue.load(file='cover-template.svg')
# replace date
tpl.set_text('sample-text', args.text)
# replace the pink box with 'hello.png'. if you do not specify the mimetype,
# the image will get linked instead of embedded
tpl.set_image('yellow-box', file=args.image)
# to render the template, cast it to a string. this also allows passing it
# as a parameter to set_svg() of another template
src = str(tpl)
# write out the result as an SVG image and render it to pdf using cairosvg
with open('cover.pdf', 'w') as out:
cairosvg.svg2pdf(bytestring=src, write_to=out)