def pdf(url: str):
"""
Generate a PDF file with the presentation.
"""
try:
code = request.urlopen(url).getcode()
except URLError:
raise ValueError('Invalid URL provided!')
if code != 200:
raise ValueError('Unexpected server response!')
with TemporaryDirectory() as tmpdir:
name = 'slides.pdf'
tmpdir = Path(tmpdir)
command = 'docker run --user={uid}:{gid} --rm --net="host" ' + \
'-v {tmp}:{tmp}:Z -w {tmp} astefanutti/decktape ' + \
'{url} {name}'
command = command.format(
uid=os.getuid(),
gid=os.getgid(),
tmp=tmpdir,
url=url,
name=name,
)
run(shlex.split(command))
move(str(tmpdir/name), str(Path.cwd()))
评论列表
文章目录