Here’s how to get an Environment Canada weather forecast from the command line. First, some sample output:
Edmonton (Int'l Aprt) - Weather - Environment Canada
No watches or warnings in effect, Edmonton (Int'l Aprt)
Current Conditions: Mostly Cloudy, -6.0 C
Monday: Chance of flurries. Temperature steady near -5. POP 30%
Monday night: Chance of flurries. Low -13. POP 30%
Tuesday: Chance of flurries. High -7. POP 30%
Tuesday night: Clear. Low -15.
Wednesday: Sunny. High -8.
Wednesday night: Clear. Low -16.
Thursday: Sunny. High -8.
Thursday night: Clear. Low -11.
Friday: Sunny. High +2.
Friday night: Clear. Low -10.
Saturday: Sunny. High +2.
Saturday night: Clear. Low -9.
Sunday: Sunny. High zero.
The code grabs the following RSS URL and then parses and formats it. Change the province and city code as needed:
And here’s the code, which colourizes the current day using ANSI escape sequences:
# Gets and parses the forecast from the Weather Office RSS
curl -s https://weather.gc.ca/rss/city/ab-71_e.xml | grep title | \
sed -e 's,</title>,,g' \
-e 's,<title>,,g' \
-e 's,^ *,,g' \
-e "s,$DAY,\x1B[1;34m$DAY\x1B[0m,g" \
-e "s,Current Conditions,\x1B[1;35mCurrent Conditions\x1B[0m,g" \
-e "s,minus ,-,g" \
-e "s,plus ,+,g" \
If you’ve been using my weather page recently, then maybe you’ve been wondering what’s going on. Like, why are days repeating themselves? It’s producing some interesting graphs, like the following:
Well my script actually broke a few days ago because the maintainer of the EAS weather station dropped a few variables from the output of the station. So, I noticed this and promptly fixed the script. But it seems that for some reason, the timestamps on the data are no longer working right. So my script, which relies on their data, happily takes the timestamps and sends them to gnuplot. The cool thing about gnuplot is that it will take date and time information as a variable and stick the data points in the right place. So, in a case like this, where the timestamps are messed up, you get interesting plots like the one above. I’m not sure if the maintainer of the EAS weather station will notice this problem since they only plot the last 24 hours on their web page. But it’s going to mess up their archives of the data.
Now I have been working on a pure Python implementation of my weather scripts which relies on METAR reports from airports. It’s working well, and since I’ve started using the PyMETAR module, I’ve been able to generalize my scripts to any airport around the world. But so far, it’s still in the testing phase and hasn’t gone online yet.