Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Wrap tweets neatly at 32 characters #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down Expand Up @@ -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