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.

87 lines
2.5 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__)
# Set up a JSON database for storing printed items
db_path = 'printed.json'
db = televex.database(db_path)
# Connect to the printer
lp = televex.connect()
# 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/3'
response = urllib.request.urlopen(url).read()
feed = json.loads(response)
except:
feed = []
for post in feed:
source = post['feed_details']['rss']
# only print toots for now (this is a test)
if 'post.lurk.org' in source:
txt, date = televex.preprocess(post, type='rss')
already_in_db = televex.update_db(db, db_path, txt, source, date)
if already_in_db == False:
televex.print_now(txt, lp=lp, type='rss')
@APP.route('/', methods=['GET'])
def index():
return flask.render_template('index.html')
@APP.route('/southexplorer/', methods=['GET', 'POST'])
def print():
txt_normal = request.args.get('normal', '')
txt_big = request.args.get('big', '')
img = request.files.get('img')
if txt_normal:
source = 'TeleVex'
txt, date = televex.preprocess(txt_normal, type='txt')
televex.update_db(db, db_path, txt_normal, source, date)
televex.print_now(txt_normal, lp=lp, type='txt', size='normal')
return flask.redirect(flask.url_for('print'))
elif txt_big:
source = 'TeleVex'
txt_big, date = televex.preprocess(txt_big, type='txt')
televex.update_db(db, db_path, txt_big, source, date)
televex.print_now(txt_big, lp=lp, type='txt', size='big')
return flask.redirect(flask.url_for('print'))
elif img:
source = 'TeleVex'
img, date = televex.preprocess(img, type='img')
televex.update_db(db, db_path, 'IMAGE', source, date)
televex.print_now(img, lp=lp, type='img')
return flask.redirect(flask.url_for('print'))
return flask.render_template('print.html')
@APP.route('/printed/', methods=['GET'])
def printed():
db = televex.database(db_path)
return flask.render_template('printed.html', items=db)
if __name__ == '__main__':
APP.debug=True
APP.run(port=5000)