Browse Source

uploading this to the git to start sharing this prototype

pull/30/head
manetta 3 years ago
commit
64e34e41cf
  1. 3
      requirements.txt
  2. 64
      start.py
  3. 21
      templates/base.html
  4. 5
      templates/html.html
  5. 5
      templates/pad.html
  6. 6
      templates/pdf.html
  7. 6
      templates/stylesheet.html

3
requirements.txt

@ -0,0 +1,3 @@
flask
etherpump
weasyprint

64
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)

21
templates/base.html

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="utf-8" />
<title>post-script</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css')}}">
</head>
<body>
<h1>post-script</h1>
<div id="nav">
<a href="/">pad</a>: <input type="text" name="pad" value="https://pad.vvvvvvaria.org/post-script.md">,
<a href="/html/">html</a>,
<a href="/pdf/">pdf</a>,
<a href="/stylesheet/">stylesheet</a>: <input type="text" name="pad" value="https://pad.vvvvvvaria.org/post-script.css">,
</div>
<div id="wrapper">
{% block content %}
{% endblock %}
</div>
</body>
</html>

5
templates/html.html

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
<iframe src="{{ url_for('static', filename='post-script.html')}}"></iframe>
{% endblock %}

5
templates/pad.html

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
<iframe src="https://pad.vvvvvvaria.org/post-script.md"></iframe>
{% endblock %}

6
templates/pdf.html

@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block content %}
<iframe src="{{ url_for('static', filename='post-script.pdf')}}"></iframe>
{% endblock %}

6
templates/stylesheet.html

@ -0,0 +1,6 @@
{% extends "base.html" %}
{% block content %}
<iframe src="https://pad.vvvvvvaria.org/post-script.css"></iframe>
{% endblock %}
Loading…
Cancel
Save