Experimental communication tools (televex screen + televex print) https://televex.vvvvvvaria.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

# 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
from escpos import printer
from tools.televex import televex
# Create the application.
APP = flask.Flask(__name__)
# Connect to the printer
lp, lp_printer = televex.connect()
# Set up a JSON database for storing printed items
db = televex.database('printed.json')
# Check the Multifeeder regulary (every 10 min)
# https://github.com/viniciuschiele/flask-apscheduler
# Thanks Crunk for pointing to this extention!
scheduler = flask_apscheduler.APScheduler()
scheduler.api_enabled = False
scheduler.init_app(APP)
scheduler.start()
@scheduler.task('interval', id='check', minutes=1)
def check():
try:
url = 'https://multi.vvvvvvaria.org/API/latest/10'
response = urllib.request.urlopen(url).read()
feed = json.loads(response)
except:
feed = []
for post in feed:
source = post['feed_details']['rss']
txt = post['summary']
televex.print_now(txt, source, db, post=post, lp=lp, lp_printer=lp_printer)
@APP.route('/print/', methods=['GET', 'POST'])
def print():
txt = request.args.get('printing', '')
if txt:
source = 'TeleVex'
televex.print_now(txt, source, db, lp=lp, lp_printer=lp_printer)
return flask.redirect(flask.url_for('print'))
return flask.render_template('index.html')
@APP.route('/printed/', methods=['GET'])
def printed():
items = json.loads(open(db).read())
return flask.render_template('printed.html', items=items)
if __name__ == '__main__':
APP.debug=True
APP.run(port=5000)