dance around silliness in twitter api. fix tweet detail barcodes

workspace
Brendan Howell 4 years ago
parent f179c606b1
commit 21b97bf189

@ -150,7 +150,6 @@ class PublicRelations(Bureau):
prn = self._get_small_printer()
# TODO: abstract this to use a simple templating system instead of raw
# TODO: add fancier formatting i.e. inverted text for username/handle
tweets = self.t.t.statuses.home_timeline(count=count,
tweet_mode="extended")
out = ""
@ -159,7 +158,12 @@ class PublicRelations(Bureau):
username = t["user"]["name"]
prn.textln(username)
prn.set()
twtext = html.unescape(t["full_text"])
if "retweeted_status" in t:
rt = t["retweeted_status"]
twtext = "RT from " + rt["user"]["name"] + "\n"
twtext += html.unescape(rt["full_text"])
else:
twtext = html.unescape(t["full_text"])
prn.block_text(twtext, font="0")
prn.ln()
@ -178,6 +182,8 @@ class PublicRelations(Bureau):
tw_shortcode = self.short_tweet_id(t["id_str"])
#prn.barcode("PRtwd." + tw_shortcode, "CODE128", function_type="B")
#TODO: submit a patch to escpos to have a quiet_zone parameter
# as the default is a bit wide for 58mm printers
prn.soft_barcode("code128", "PRtwd." + tw_shortcode, module_width=0.16)
prn.ln(2)
@ -198,7 +204,12 @@ class PublicRelations(Bureau):
username = tweet["user"]["name"]
prn.textln(username)
prn.set()
twtext = html.unescape(tweet["full_text"])
if "retweeted_status" in tweet:
rt = tweet["retweeted_status"]
twtext = "RT from " + rt["user"]["name"] + "\n"
twtext += html.unescape(rt["full_text"])
else:
twtext = html.unescape(tweet["full_text"])
prn.block_text(twtext, font="0")
if "media" in tweet["entities"]:
@ -217,13 +228,13 @@ class PublicRelations(Bureau):
tw_shortcode = self.short_tweet_id(tweet["id_str"])
prn.text("retweet\r\n")
#prn.barcode("PRtwrt." + tw_shortcode, "CODE128", function_type="B")
prn.soft_barcode("code128", "PRtwrt." + tw_shortcode)
prn.soft_barcode("code128", "PRtwrt." + tw_shortcode, module_width=0.16)
prn.text("like\r\n")
#prn.barcode("PRtwlk." + tw_shortcode, "CODE128", function_type="B")
prn.soft_barcode("code128", "PRtwlk." + tw_shortcode)
prn.soft_barcode("code128", "PRtwlk." + tw_shortcode, module_width=0.16)
prn.text("\r\n\r\n")
#prn.barcode("PRtwre." + tw_shortcode, "CODE128", function_type="B")
prn.soft_barcode("code128", "PRtwre." + tw_shortcode)
prn.soft_barcode("code128", "PRtwre." + tw_shortcode, module_width=0.16)
prn.ln(2)
prn.cut()
prn.close()
@ -298,7 +309,6 @@ class PublicRelations(Bureau):
count = 10
prn = self._get_small_printer()
prn.codepage = "cp437"
# TODO: add fancier formatting i.e. inverted text for username/handle
# TODO: clean this up to use the built in formatting from escpos lib
@ -321,9 +331,6 @@ class PublicRelations(Bureau):
if media.type == "image":
img = media
if img:
#filename = img.url.rsplit('/',1)[1]
#filename = "/tmp/" + filename
#print("fetching", img.remote_url, filename)
req_data = requests.get(img.url)
im = PIL.Image.open(io.BytesIO(req_data.content))
if im.mode in ("L", "RGB", "P"):
@ -333,7 +340,7 @@ class PublicRelations(Bureau):
tw_shortcode = self.short_tweet_id(str(t["id"]))
#prn.barcode("PRmad." + tw_shortcode, "CODE128", function_type="B")
prn.soft_barcode("code128", "PRmad." + tw_shortcode)
prn.soft_barcode("code128", "PRmad." + tw_shortcode, module_width=0.16)
notifications = self.masto.notifications(since_id=self.last_mast_notif)
if len(notifications) > 0:

Loading…
Cancel
Save