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

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

Loading…
Cancel
Save