From ccd922927b16bdedf128ff6e3cdf9d3e9246a3a1 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Mon, 6 Jul 2020 22:41:11 +0200 Subject: [PATCH] fix publications error handling. add mini weather --- .../bureau/publications/publications.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/screenless/bureau/publications/publications.py b/screenless/bureau/publications/publications.py index 6261393..9c867bc 100644 --- a/screenless/bureau/publications/publications.py +++ b/screenless/bureau/publications/publications.py @@ -130,6 +130,28 @@ class Publications(Bureau): self.print_full("news.html", news=news, inbox=inbox, date=date, forecast=forecast) + @add_command("wttr", "Print out the local weather forecast") + def print_weather(self): + """ + Use the small printer to output the current local weather forecast + pulled from met.no api. + """ + lat, lon = self.config["latlon"] + forecast = weather.get_forecast(lat, lon) + prn = self._get_small_printer() + prn.text("CURRENT WEATHER\r\n") + day_count = 0 + current = "Today" + for period in forecast: + if period["day"] != current: + prn.text(period["day"]) + day_count += 1 + self.print_small_image(period["png"]) + prn.text(" - " + period["period"] + "\r\n") + prn.text(period["mintemp"] + " - " + period["maxtemp"] + "°") + if day_count > 3: + break + @add_command("r", "Print a web page for reading") def print_url(self, data): """ @@ -342,7 +364,7 @@ class Publications(Bureau): print("fetching", entry.img, filename) urllib.request.urlretrieve(entry.img, filename) entry.img = "file://" + filename - except urllib.error.HTTPError, ValueError as err: + except (urllib.error.HTTPError, ValueError) as err: self.log.error(err) entry.img = " "