From 64b8fa76023f69747bcc0870bbcc53b06441c81b Mon Sep 17 00:00:00 2001 From: Gareth Halfacree Date: Tue, 6 Aug 2013 11:10:19 +0100 Subject: [PATCH] Wrap tweets neatly at 32 characters --- twitter.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/twitter.py b/twitter.py index 4b579d7..1c4dabd 100755 --- a/twitter.py +++ b/twitter.py @@ -27,7 +27,7 @@ # with dummy strings. from __future__ import print_function -import base64, HTMLParser, httplib, json, sys, urllib, zlib +import base64, HTMLParser, httplib, json, sys, urllib, zlib, textwrap from unidecode import unidecode from Adafruit_Thermal import * @@ -113,9 +113,11 @@ def issueRequestAndDecodeResponse(method, url, body, headers): # Remove HTML escape sequences # and remap Unicode values to nearest ASCII equivalents - printer.print(unidecode( - HTMLParser.HTMLParser().unescape(tweet['text']))) - + # Use textwrap module to wrap neatly at 32 characters + tweettext=textwrap.wrap(unidecode( + HTMLParser.HTMLParser().unescape(tweet['text'])),32) + for line in tweettext: + printer.print(line + "\n") printer.feed(3) print(data['search_metadata']['max_id_str']) # Piped back to calling process