Canadian Weather for Asterisk users (UPDATED)
First off, let me thank the original creator of this page, mbuckway, for he showed me the way and I simply brought it to 2015 (and Asterisk 11). I, in NO WAY, take full credit for this page. I simply updated it. All thanks go to him!
Many Asterisk installations (Asterisk@Home, TrixBox etc.) come out of the box with *61 setup to generate weather for US cities. This is all fine and good if you live in the US, but what about all of us up here in the Great White North? With the assistance of an older post http://lists.digium.com/pipermail/asterisk-users/2005-September/117619.html, we managed to create a workable script to generate weather from the Environment Canada website.
(NOTE: since the creation of this page, Environment Canda has gone through many changes. Links and the original script that used to work from here did NOT work anymore, hence why I updated this page.)
The steps to add weather to your Asterisk installation are as follows:
1. Save the script into /usr/lib/asterisk (or other suitable location) named "weather"
2. Modify it to produce weather for your Canadian City (see https://weather.gc.ca/forecast/public_bulletins_e.html). We generated a cleaned up text file for it to run text2wave over below.
3. Setup a cron job to run hourly. (while you could set it to run when you type *61, the weather never updates very often and that means a 2-6 sec wait to generate the weather file - so, we opted for an offline approach)
4. Modify extensions_custom.conf to change it to playback the weather file.
ON TO THE NITTY GRITTY!!! :D
1. Use your favorite editor (eg: nano weather) and create the file called "weather" into /usr/lib/asterisk. (for smooth flow of these instructions)
2. Copy and paste the script below and change the city names to your city/town as listed in the text file from Environment Canada at https://weather.gc.ca/forecast/public_bulletins_e.html. Click on your province, then scroll the text file until you see something like this (but with your city as the title):
City of Ottawa
Gatineau
Prescott and Russell
Cornwall - Morrisburg.
Tonight..Mainly cloudy. Low plus 5.
Thursday..A mix of sun and cloud. High 15. UV index 6 or high.
Thursday night..Mainly cloudy. Low plus 5.
The script to paste and modify into the "weather" file is as follows (REMEMBER: change the Ottawa references to your city name as it appears in the bulletin):
#/bin/bash
rm -f /var/lib/asterisk/sounds/weather.ulaw
echo "Ottawa forecast"> /tmp/weather2.$$
wget -O /tmp/weather.$$ -q https://weather.gc.ca/forecast/public_bulletins_e.html?Bulletin=fpcn11.cwto
grep -A3 "City of Ottawa" /tmp/weather.$$ >> /tmp/weather2.$$
echo "end of forecast">> /tmp/weather2.$$
sed "s/\.\./ /" /tmp/weather2.$$ | text2wave -o /var/lib/asterisk/sounds/en/weather.ulaw -otype ulaw
rm -f /tmp/weather.$$ /tmp/weather2.$$
IMPORTANT: Make sure to type "chmod +x weather" to make the script executeable!!!
3. At a shell prompt, type crontab -e and add the following line:
0 * * * * /usr/lib/asterisk/weather
4. Now add the following lines to extensions_custom.conf:
exten => *61,1,Answer
exten => *61,2,Playback(weather) - this is the name of the ulaw file that will be played when *61 is dialled
;exten => *61,2,AGI(weather.agi) - comment out or remove the AGI line should it be present
exten => *61,3,Hangup
Sometime in the next hour, on the hour, it will execute the file and then you have your weather forecast!
(or type ./usr/lib/asterisk/weather to run it immediately)
Cheers!!!
First off, let me thank the original creator of this page, mbuckway, for he showed me the way and I simply brought it to 2015 (and Asterisk 11). I, in NO WAY, take full credit for this page. I simply updated it. All thanks go to him!
Many Asterisk installations (Asterisk@Home, TrixBox etc.) come out of the box with *61 setup to generate weather for US cities. This is all fine and good if you live in the US, but what about all of us up here in the Great White North? With the assistance of an older post http://lists.digium.com/pipermail/asterisk-users/2005-September/117619.html, we managed to create a workable script to generate weather from the Environment Canada website.
(NOTE: since the creation of this page, Environment Canda has gone through many changes. Links and the original script that used to work from here did NOT work anymore, hence why I updated this page.)
The steps to add weather to your Asterisk installation are as follows:
1. Save the script into /usr/lib/asterisk (or other suitable location) named "weather"
2. Modify it to produce weather for your Canadian City (see https://weather.gc.ca/forecast/public_bulletins_e.html). We generated a cleaned up text file for it to run text2wave over below.
3. Setup a cron job to run hourly. (while you could set it to run when you type *61, the weather never updates very often and that means a 2-6 sec wait to generate the weather file - so, we opted for an offline approach)
4. Modify extensions_custom.conf to change it to playback the weather file.
ON TO THE NITTY GRITTY!!! :D
1. Use your favorite editor (eg: nano weather) and create the file called "weather" into /usr/lib/asterisk. (for smooth flow of these instructions)
2. Copy and paste the script below and change the city names to your city/town as listed in the text file from Environment Canada at https://weather.gc.ca/forecast/public_bulletins_e.html. Click on your province, then scroll the text file until you see something like this (but with your city as the title):
City of Ottawa
Gatineau
Prescott and Russell
Cornwall - Morrisburg.
Tonight..Mainly cloudy. Low plus 5.
Thursday..A mix of sun and cloud. High 15. UV index 6 or high.
Thursday night..Mainly cloudy. Low plus 5.
The script to paste and modify into the "weather" file is as follows (REMEMBER: change the Ottawa references to your city name as it appears in the bulletin):
#/bin/bash
rm -f /var/lib/asterisk/sounds/weather.ulaw
echo "Ottawa forecast"> /tmp/weather2.$$
wget -O /tmp/weather.$$ -q https://weather.gc.ca/forecast/public_bulletins_e.html?Bulletin=fpcn11.cwto
grep -A3 "City of Ottawa" /tmp/weather.$$ >> /tmp/weather2.$$
echo "end of forecast">> /tmp/weather2.$$
sed "s/\.\./ /" /tmp/weather2.$$ | text2wave -o /var/lib/asterisk/sounds/en/weather.ulaw -otype ulaw
rm -f /tmp/weather.$$ /tmp/weather2.$$
IMPORTANT: Make sure to type "chmod +x weather" to make the script executeable!!!
3. At a shell prompt, type crontab -e and add the following line:
0 * * * * /usr/lib/asterisk/weather
4. Now add the following lines to extensions_custom.conf:
exten => *61,1,Answer
exten => *61,2,Playback(weather) - this is the name of the ulaw file that will be played when *61 is dialled
;exten => *61,2,AGI(weather.agi) - comment out or remove the AGI line should it be present
exten => *61,3,Hangup
Sometime in the next hour, on the hour, it will execute the file and then you have your weather forecast!
(or type ./usr/lib/asterisk/weather to run it immediately)
Cheers!!!