From 6e3f0e75adb7be0c36f87d9c3c5641d74e66202b Mon Sep 17 00:00:00 2001 From: televex Date: Thu, 25 Feb 2021 09:16:00 +0000 Subject: [PATCH] testing to print multifeeder posts --- .gitignore | 1 + print/start.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 0615e89..7845bcd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ venv* *__pycache__* *.pyc print/printed.json +screen/tools/ascii-art-but-with-unicode/asciiWriter/__pycache__/* diff --git a/print/start.py b/print/start.py index f3cc3e3..dab55f9 100644 --- a/print/start.py +++ b/print/start.py @@ -37,10 +37,14 @@ scheduler.start() def update_db(item): items = json.loads(open(db).read()) if not item in items['printed']: + new_item = True with open(db, 'w') as out: items['printed'].append(item) out.write(json.dumps(items, indent=4)) out.close() + else: + new_item = False + return new_item def html2plain(html): plain = re.sub('<[^<]+?>', '', text) @@ -48,8 +52,6 @@ def html2plain(html): @scheduler.task('interval', id='check', minutes=10) def check(): - print('Checking the Multifeeder!') - url = 'https://multi.vvvvvvaria.org/API/latest/10' response = urllib.request.urlopen(url).read() feed = json.loads(response) @@ -66,7 +68,13 @@ def check(): 'date' : post_date, 'printed' : plaintext } - update_db(item) + new_item = update_db(item) + if new_item == True: + # print RSS post + buffer.text(plaintext) + buffer.cut() + lp._raw(buffer.output) + @APP.route('/print/', methods=['GET', 'POST']) def print(): @@ -83,7 +91,6 @@ def print(): date = datetime.now() date_str = date.strftime('%Y-%m-%d_%H-%M-%S') - item = { 'source' : 'TeleVex', 'date' : date_str, @@ -95,9 +102,7 @@ def print(): @APP.route('/printed/', methods=['GET', 'POST']) def printed(): - items = json.loads(open(db).read()) - return flask.render_template('printed.html', items=items) if __name__ == '__main__':