diff --git a/render.py b/render.py
index ec886a7..6325197 100644
--- a/render.py
+++ b/render.py
@@ -7,6 +7,7 @@ import time
import cairocffi as cairo
import flask
+from flask import json
import pangocffi as pango
import pangocairocffi as pangocairo
@@ -59,8 +60,7 @@ class Renderer(object):
layout.apply_markup('%s' % (fontname, text))
else:
font = pango.FontDescription()
- font.family = "Sans"
- font.size = 65
+ font.family = fontname
layout.font_description = font
layout.text = text
@@ -81,10 +81,10 @@ def healthcheck():
last_checked, last_status, last_details = app.health
if time.time() - last_checked < 1:
return last_status, last_details
- output = subprocess.check_output(['lpstat', '-p', '-d'])
+ output = subprocess.run(['lpstat', '-p', '-d'], capture_output=True).stdout
mark = False
- for line in output.split('\n'):
- line = line.strip()
+ for line in output.split(b'\n'):
+ line = line.strip().decode('utf-8')
if line.startswith('printer DYMO_LabelWriter_450'):
if 'is idle.' in line:
return True, 'Idle'
@@ -98,13 +98,13 @@ def healthcheck():
app.health = (time.time(), False, line)
return False, line
mark = False
+ return False, 'Printer is down or there\'s something wrong with lpstat output.'
-# TODO: Uncomment and fix this
-# @app.route('/health')
-# def health():
-# ok, details = healthcheck()
-# return json.dumps({'ok': ok, 'details': details})
+@app.route('/health')
+def health():
+ ok, details = healthcheck()
+ return json.dumps({'ok': ok, 'details': details})
@app.route('/stuff/preview//')
def stuff_preview(size):
@@ -124,7 +124,7 @@ def stuff_print(size):
if not healthcheck()[0]:
return 'Printer is down.'
last = app.last
- print(last, time.time() - last)
+ print((last, time.time() - last))
if time.time() - last < DELAY:
return 'Please wait {} more seconds before next print.'.format(int(DELAY - (time.time() - last)))
text = flask.request.args.get('text')