Add code for printing RTs on the thermal printer
This commit is contained in:
parent
c7720f6c85
commit
eb5991468b
13
printer.py
13
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):
|
||||
|
|
Loading…
Reference in New Issue