#!/usr/bin/env python import json import logging from flask import Flask, request, make_response from weasyprint import HTML app = Flask('pdf') @app.route('/health') def index(): return 'ok' @app.before_first_request def setup_logging(): logging.addLevelName(logging.DEBUG, "\033[1;36m%s\033[1;0m" % logging.getLevelName(logging.DEBUG)) logging.addLevelName(logging.INFO, "\033[1;32m%s\033[1;0m" % logging.getLevelName(logging.INFO)) logging.addLevelName(logging.WARNING, "\033[1;33m%s\033[1;0m" % logging.getLevelName(logging.WARNING)) logging.addLevelName(logging.ERROR, "\033[1;31m%s\033[1;0m" % logging.getLevelName(logging.ERROR)) handler = logging.StreamHandler() handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s: %(message)s ' '[in %(pathname)s:%(lineno)d]' )) app.logger.addHandler(handler) app.logger.setLevel(logging.DEBUG) @app.route('/') def home(): return '''
The following endpoints are available:
/pdf?filename=myfile.pdf. The body should
contain html/multiple?filename=myfile.pdf. The body
should contain a JSON list of html strings. They will each
be rendered and combined into a single pdf