Here’s how to get an Environment Canada weather forecast from the command line. First, some sample output:
darren@unity:~% forecast 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:
#!/bin/sh # # Gets and parses the forecast from the Weather Office RSS # URL='https://weather.gc.ca/rss/city/ab-71_e.xml' DAY=`date +%A` curl -s $URL | grep title | cut -c 9- | \ sed -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" \