refactor to take advantage of built-in barcode and encoding in escpos library

workspace
Brendan Howell 4 years ago
parent 75c51cc7db
commit 93c0c57058

@ -140,7 +140,7 @@ class Publications(Bureau):
lat, lon = self.config["latlon"] lat, lon = self.config["latlon"]
forecast = weather.get_forecast(lat, lon) forecast = weather.get_forecast(lat, lon)
prn = self._get_small_printer() prn = self._get_small_printer()
prn.text("CURRENT WEATHER\r\n") prn.textln("CURRENT WEATHER")
day_count = 0 day_count = 0
current = "Today" current = "Today"
for period in forecast: for period in forecast:
@ -149,11 +149,9 @@ class Publications(Bureau):
prn.text(period["day"]) prn.text(period["day"])
if period["day"] != current: if period["day"] != current:
day_count += 1 day_count += 1
prn.text(" - " + period["period"] + "\r\n") prn.textln(" - " + period["period"])
prn.close() prn.image(period["png"])
self.print_small_image(period["png"]) prn.textln(period["mintemp"] + " - " + period["maxtemp"] + "°C")
prn = self._get_small_printer()
prn.text(period["mintemp"] + " - " + period["maxtemp"] + "C\r\n")
if day_count > 4: if day_count > 4:
break break
prn.ln() prn.ln()

@ -155,10 +155,10 @@ class PublicRelations(Bureau):
tweet_mode="extended") tweet_mode="extended")
out = "" out = ""
for t in tweets: for t in tweets:
prn.set(text_type="U") prn.set(underline=1)
username = t["user"]["name"] username = t["user"]["name"]
prn.textln(username) prn.textln(username)
prn.set(text_type="NORMAL") prn.set()
twtext = html.unescape(t["full_text"]) twtext = html.unescape(t["full_text"])
prn.block_text(twtext) prn.block_text(twtext)
prn.ln() prn.ln()
@ -194,10 +194,10 @@ class PublicRelations(Bureau):
tweet = self.t.t.statuses.show(id=tweet_id, tweet_mode="extended") tweet = self.t.t.statuses.show(id=tweet_id, tweet_mode="extended")
prn = self._get_small_printer() prn = self._get_small_printer()
prn.set(text_type="U") prn.set(underline=1)
username = tweet["user"]["name"] username = tweet["user"]["name"]
prn.textln(username) prn.textln(username)
prn.set(text_type="NORMAL") prn.set()
twtext = html.unescape(tweet["full_text"]) twtext = html.unescape(tweet["full_text"])
prn.block_text(twtext) prn.block_text(twtext)
@ -306,10 +306,10 @@ class PublicRelations(Bureau):
toots = self.masto.timeline(limit=count) toots = self.masto.timeline(limit=count)
out = "" out = ""
for t in toots: for t in toots:
prn.set(text_type="U") prn.set(underline=1)
username = t.account.display_name username = t.account.display_name
prn.textln(username) prn.textln(username)
prn.set(text_type="NORMAL") prn.set()
ttext = bleach.clean(t.content, tags=[], strip=True) ttext = bleach.clean(t.content, tags=[], strip=True)
ttext = html.unescape(ttext) ttext = html.unescape(ttext)
prn.block_text(ttext) prn.block_text(ttext)
@ -337,9 +337,9 @@ class PublicRelations(Bureau):
notifications = self.masto.notifications(since_id=self.last_mast_notif) notifications = self.masto.notifications(since_id=self.last_mast_notif)
if len(notifications) > 0: if len(notifications) > 0:
prn.set(text_type="B") prn.set(bold=True)
prn.textln("NOTIFICATIONS:") prn.textln("NOTIFICATIONS:")
prn.set(text_type="NORMAL") prn.set()
# store the last notification id # store the last notification id
self.last_mast_notif = str(notifications[0].id) self.last_mast_notif = str(notifications[0].id)

Loading…
Cancel
Save