From 64e34e41cf1a11afab92a0f859f0d68adbcaa48b Mon Sep 17 00:00:00 2001 From: manetta Date: Thu, 24 Jun 2021 14:04:14 +0200 Subject: [PATCH] uploading this to the git to start sharing this prototype --- requirements.txt | 3 ++ start.py | 64 +++++++++++++++++++++++++++++++++++++++ templates/base.html | 21 +++++++++++++ templates/html.html | 5 +++ templates/pad.html | 5 +++ templates/pdf.html | 6 ++++ templates/stylesheet.html | 6 ++++ 7 files changed, 110 insertions(+) create mode 100644 requirements.txt create mode 100755 start.py create mode 100644 templates/base.html create mode 100644 templates/html.html create mode 100644 templates/pad.html create mode 100644 templates/pdf.html create mode 100644 templates/stylesheet.html diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5715165 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +flask +etherpump +weasyprint diff --git a/start.py b/start.py new file mode 100755 index 0000000..e8b4a6a --- /dev/null +++ b/start.py @@ -0,0 +1,64 @@ +# https://github.com/python-escpos/python-escpos +# https://python-escpos.readthedocs.io/en/latest/ + +import flask +from flask import request +# import flask_apscheduler +import urllib, json +import os + +# Create the application. +APP = flask.Flask(__name__) + +# Recurrent actions +# scheduler = flask_apscheduler.APScheduler() +# scheduler.api_enabled = False +# scheduler.init_app(APP) +# scheduler.start() + +# @scheduler.task('interval', id='check', minutes=1) +# def action(): +# print('Do something recurrent') + +pads = [ + 'post-script.md', + 'post-script.css' + ] +DIR_PATH = '/home/mb/post-script-interface' + +def download(pads): + # using etherpump + for pad in pads: + os.system(f'{ DIR_PATH }/venv/bin/etherpump gettext { pad } > { DIR_PATH }/static/{ pad }') + +@APP.route('/', methods=['GET']) +def pad(): + return flask.render_template('pad.html') + +@APP.route('/html/', methods=['GET', 'POST']) +def html(): + # download the main post-script pad + stylesheet pad + download(pads) + # generate html page + os.system(f'pandoc -f markdown -t html -c post-script.css --toc --toc-depth=1 --standalone { DIR_PATH }/static/post-script.md -o { DIR_PATH }/static/post-script.html') + + return flask.render_template('html.html') + +@APP.route('/pdf/', methods=['GET']) +def pdf(): + # download the main post-script pad + stylesheet pad + download(pads) + # generate html page + os.system(f'pandoc -f markdown -t html -c post-script.css --toc --toc-depth=1 --standalone { DIR_PATH }/static/post-script.md -o { DIR_PATH }/static/post-script.html') + # generate pdf + os.system(f'{ DIR_PATH }/venv/bin/weasyprint -s { DIR_PATH }/static/post-script.css { DIR_PATH }/static/post-script.html { DIR_PATH }/static/post-script.pdf') + + return flask.render_template('pdf.html') + +@APP.route('/stylesheet/', methods=['GET']) +def stylesheet(): + return flask.render_template('stylesheet.html') + +if __name__ == '__main__': + APP.debug=True + APP.run(port=5577) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..9fa8fcd --- /dev/null +++ b/templates/base.html @@ -0,0 +1,21 @@ + + + + + post-script + + + +

post-script

+ +
+ {% block content %} + {% endblock %} +
+ + diff --git a/templates/html.html b/templates/html.html new file mode 100644 index 0000000..125987c --- /dev/null +++ b/templates/html.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} + +{% endblock %} diff --git a/templates/pad.html b/templates/pad.html new file mode 100644 index 0000000..1cc8fff --- /dev/null +++ b/templates/pad.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} + +{% endblock %} diff --git a/templates/pdf.html b/templates/pdf.html new file mode 100644 index 0000000..268d605 --- /dev/null +++ b/templates/pdf.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} + +{% block content %} + +{% endblock %} + diff --git a/templates/stylesheet.html b/templates/stylesheet.html new file mode 100644 index 0000000..3e42e5b --- /dev/null +++ b/templates/stylesheet.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} + +{% block content %} + +{% endblock %} +