fix publications error handling. add mini weather

workspace
Brendan Howell 4 years ago
parent 5915728a2f
commit ccd922927b

@ -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 = " "

Loading…
Cancel
Save