This past summer, I updated the MotD of my Orange Pi to include the current weather whenever I log in. It worked great… until recently. For the past week or so, I noticed it wasn’t showing the weather when I logged in.
It turned out to be a simple error and easy fix. The command works by downloading the current weather from the Internet, then using SED to scrape the current temperature and status from the resulting page using a regex.
The problem is that it does not account for negative temperatures, which is what the temperatures are now in the winter (at least in Celsius), so when the temperature is below zero, it does not find the information because the pattern does not match. The fix is simply adding an optional negative sign (-\?) to the regex (optional in the regex sense; it’s required to make this work correctly):
root:/> more /etc/update-motd.d/32-weather #!/bin/bash curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=NAM|CA|ON|LONDON|" |\ sed -n '/Currently:/ s/.*: \(.*\): \(-\?[0-9]*\)\([CF]\).*/\2°\3, \1/p'