From 29de91d8edecf0f882108e3143673a05a2af8ac4 Mon Sep 17 00:00:00 2001 From: manetta Date: Wed, 24 Feb 2021 17:19:57 +0100 Subject: [PATCH] making a start of the print section of TeleVex --- .gitignore | 2 ++ .gitmodules | 4 +-- Makefile | 11 +++++++ print/start.py | 52 +++++++++++++++++++++++++++++++ print/static/stylesheet.css | 16 ++++++++++ print/templates/index.html | 43 +++++++++++++++++++++++++ requirements.txt | 2 +- televex.py => screen/televex.py | 0 {texts => screen/texts}/about.txt | 0 tools/ascii-art-but-with-unicode | 1 - 10 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 Makefile create mode 100644 print/start.py create mode 100644 print/static/stylesheet.css create mode 100644 print/templates/index.html rename televex.py => screen/televex.py (100%) rename {texts => screen/texts}/about.txt (100%) delete mode 160000 tools/ascii-art-but-with-unicode diff --git a/.gitignore b/.gitignore index 9e3d04c..784ffa0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +.venv* venv* +print/__pycache__* diff --git a/.gitmodules b/.gitmodules index c1c87c9..bf4c20f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "tools/ascii-art-but-with-unicode"] - path = tools/ascii-art-but-with-unicode +[submodule "screen/tools/ascii-art-but-with-unicode"] + path = screen/tools/ascii-art-but-with-unicode url = https://git.vvvvvvaria.org/mb/ascii-art-but-with-unicode.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..db4809b --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +setup: + @python3 -m venv .venv && \ + .venv/bin/pip install -r requirements.txt + +screen: + @cd screen && \ + .venv/bin/python televex.py + +print: + $cd print && \ + .venv/bin/python start.py diff --git a/print/start.py b/print/start.py new file mode 100644 index 0000000..6ac4b1e --- /dev/null +++ b/print/start.py @@ -0,0 +1,52 @@ +# https://github.com/python-escpos/python-escpos +# https://python-escpos.readthedocs.io/en/latest/ + +import sys +import os +import flask +from flask import request +import urllib +import json +from escpos.escpos import Escpos +from escpos import printer + +# Create the application. +APP = flask.Flask(__name__) + +# File Initialization +try: + lp = printer.File("/dev/usb/lp0") +except: + lp = sys.stdout + +# USB initialization +# Bus 001 Device 006: ID 04b8:0e15 Seiko Epson Corp. +# lp = printer.Usb(0x4b8, 0xe15) + +lp.text('test :)') +lp.image('') +lp.cut() + + +@APP.route('/', methods=['GET', 'POST']) +def index(): + + plaintext = request.args.get('plaintext', '') + + if plaintext: + lp.text(plaintext) + lp.cut() + + url = 'https://multi.vvvvvvaria.org/API/latest/5' + response = urllib.request.urlopen(url).read() + multifeeder = json.loads(response) + + url = 'https://multi.vvvvvvaria.org/API/today/' + response = urllib.request.urlopen(url).read() + feedstoday = json.loads(response) + + return flask.render_template('index.html', plaintext=plaintext, multifeeder=multifeeder, feedstoday=feedstoday) + +if __name__ == '__main__': + APP.debug=True + APP.run(port=5000) \ No newline at end of file diff --git a/print/static/stylesheet.css b/print/static/stylesheet.css new file mode 100644 index 0000000..9423eb9 --- /dev/null +++ b/print/static/stylesheet.css @@ -0,0 +1,16 @@ +body{ + color:magenta; + margin:2em; +} +div#print, +div#multifeeder, +div#webcam{ + + +} +div#multifeeder div.multipost{ + margin:1em 0; +} +div#webcam img{ + width:500px; +} \ No newline at end of file diff --git a/print/templates/index.html b/print/templates/index.html new file mode 100644 index 0000000..3306727 --- /dev/null +++ b/print/templates/index.html @@ -0,0 +1,43 @@ + + + + + TeleVex (print) + + + +
+ +
+

Plain Text Printing Point (ASCII only)

+
+ +
+
+ +
+
+

Image printing access point

+
+ + +
+
+
+
+

Multifeeder

+
Last 5 posts added to the Televex print stream:
+
+ {% for post in multifeeder %} +
+ Title: {{ post.title }}
+ Link: {{ post.link }}
+ Author: {{ post.author }}
+ Date: {{ post.published }}
+
+ {% endfor %} +
+ +
+ + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 52dc9e0..b8890db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ feedparser icalendar requests pypandoc -pyhyphen +python-escpos diff --git a/televex.py b/screen/televex.py similarity index 100% rename from televex.py rename to screen/televex.py diff --git a/texts/about.txt b/screen/texts/about.txt similarity index 100% rename from texts/about.txt rename to screen/texts/about.txt diff --git a/tools/ascii-art-but-with-unicode b/tools/ascii-art-but-with-unicode deleted file mode 160000 index 8723ac9..0000000 --- a/tools/ascii-art-but-with-unicode +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8723ac945f14363581c849a2fc8b41bcd58f0af9