From eb5991468b78e1fe35c74775ff2a88704d2645f7 Mon Sep 17 00:00:00 2001 From: Daniel Schulte Date: Sun, 18 Mar 2018 18:00:23 +0100 Subject: [PATCH] Add code for printing RTs on the thermal printer --- printer.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/printer.py b/printer.py index fe84b09..3dc2fa6 100755 --- a/printer.py +++ b/printer.py @@ -171,13 +171,22 @@ class StreamListener(tweepy.StreamListener): self.seen_tweets.add(rt.id) rt_text = rt.extended_tweet["full_text"] if rt.truncated else rt.text rt_text = html.unescape(rt_text) - #print("[{}] New retweet by @{}:".format(self.title, status.user.screen_name)) - #print("@{}: {}".format(rt.user.screen_name, rt_text)) header = format_header(status.user.screen_name, status.user.name, status.created_at, is_rt=True) rt_header = format_header(rt.user.screen_name, rt.user.name, rt.created_at) print(header) print(rt_header) print(rt_text) + if self.printer: + try: + encoded_header = header.encode("latin-1") + encoded_rt_header = rt_header.encode("latin-1") + encoded_rt_text = rt_text.encode("latin-1") + self.printer.write(encoded_header) + self.printer.write(encoded_rt_header) + self.printer.write(encoded_rt_text, True, True) + self.printer.flush() + except UnicodeEncodeError: + print("Can't print. Encoding issue.") return True def on_error(self, status_code):