WX Scripts

Allstar WX scripts – rc1 V 3.1

Allstar Weather Scripts Just change the node # in each file and install Cepstral TTS or replace with your own. Then add appropriate lines to extensions.conf / rpt.conf as needed.

ex: assuming files are located in /etc/asterisk/scripts/wxzip/…

rpt.conf
97=autopatchup,context=wxzip,noct=1,farenddisconnect=1,dialtime=20000
96=autopatchup,context=wxzipf,noct=1,farenddisconnect=1,dialtime=20000

extensions.conf
[wxzip]
exten => _.,1,System(/etc/asterisk/scripts/wxzip/Current ${EXTEN})

[wxzipf]
exten => _.,1,System(/etc/asterisk/scripts/wxzip/Forecast ${EXTEN})

*Also requires Cepstral TTS voice purchase or substitute your own TTS engine.

Current:

#!/bin/bash
##################################################################
# filename: KC7DMF-Weather-Current
#
# description: Current Weather Conditions
#
# history: Version 3.1
# 09/4/2017 KC7DMF Weather Allstar
#
##################################################################
# Begin

FIL=cur
NODE=27038
VOICE=William
WX=/etc/asterisk/scripts/wxzip
ZIP=$1

/usr/sbin/asterisk -rx “rpt fun $NODE *71”;

pushd $WX;

if [ `echo ${#ZIP}` != 5 ]; then
exit 0
fi

#Get the info
lynx -dump http://forecast.weather.gov/zipcity.php?inputstring=$ZIP > $FIL.txt

#Delete all before & After
sed -i ‘/Current conditions at/,$!d’ $FIL.txt;
sed -i ‘/Last update/q’ $FIL.txt;
sed -i ‘/Lat/d’ $FIL.txt;
sed -i ‘/Barometer/ s/in/ inches /’ $FIL.txt;
sed -i ‘/Visibility/ s/mi/ Miles /’ $FIL.txt;
sed -i ‘/Dewpoint/ s/F/ Fahrenheit /’ $FIL.txt;
sed -i ‘/Heat\ Index/ s/F/ Fahrenheit /’ $FIL.txt;
sed -i ‘/Dewpoint/ s/C/ Centirgrade /’ $FIL.txt;
sed -i ‘/Heat\ Index/ s/C/ Centigrade /’ $FIL.txt;

#Wind Direction
sed -i ‘s/ NW/ North West /;s/ NE/ North East /;s/ SW/ South West /;s/ SE/ South East /’ $FIL.txt;
sed -i ‘s/ NNW/ North North West /;s/ NNE/ North North East /’ $FIL.txt;
sed -i ‘s/ SSW/ South South West /;s/ SSE/ South South East /’ $FIL.txt;
sed -i ‘s/ WNW/ West North West /;s/ WSW/ West South West /’ $FIL.txt;
sed -i ‘s/ ESE/ East South East /;s/ ENE/ East North East /’ $FIL.txt;
sed -i ‘s/\[//;s/\]//’ $FIL.txt;

#Time zones
sed -i ‘s/PDT/Pacific Daylight Time/;s/PST/Pacific Standard Time/’ $FIL.txt;
sed -i ‘s/MDT/Mountain Daylight Time/;s/MST/Mountain Standard Time/’ $FIL.txt;
sed -i ‘s/CDT/Central Daylight Time/;s/CST/Central Standard Time/’ $FIL.txt;
sed -i ‘s/EDT/Eastern Daylight Time/;s/EST/Eastern Standard Time/’ $FIL.txt;

#Fix Wind
sed -i ‘s/Wind/Whend/’ $FIL.txt;

#Deg F
sed -i ‘s/\°F/ \, /’ $FIL.txt;

#Inches
sed -i ‘s/ 1 in\. / 1 inch /’ $FIL.txt;
sed -i ‘s/ in\. / inches /’ $FIL.txt;

#NWS
sed -i ‘s/NWS/ National Weather Service /’ $FIL.txt;
sed -i ‘s/BestForecast/ Best Forecast /’ $FIL.txt;

#Generate and Speak
/opt/swift/bin/swift -n $VOICE -p audio/channels=1,audio/encoding=ulaw -f $WX/$FIL.txt -o – | cat > $WX/$FIL.ulaw& asterisk -rx “rpt playback $NODE $WX/$FIL”&

Forecast:
#!/bin/bash
##################################################################
# filename: KC7DMF-Weather-Forecast
#
# description: Weather Forecast
#
# history: Version 3.1
# 09/4/2017 KC7DMF Weather Forecast
#
##################################################################
# Begin

FIL=fcast
NODE=27038
VOICE=Allison
WX=/etc/asterisk/scripts/wxzip
ZIP=$1

/usr/sbin/asterisk -rx “rpt fun $NODE *71”;

pushd $WX;

if [ `echo ${#ZIP}` != 5 ]; then
exit 0
fi

echo “Starting”
day=$(date –date=”3 day” +”%A”)
echo $day

#Get the info
lynx -dump http://forecast.weather.gov/zipcity.php?inputstring=$ZIP > $FIL.txt

sed -i ‘/Extended Forecast for/,$!d’ $FIL.txt;
sed -i ‘/Additional Forecasts and Information/q’ $FIL.txt;
sed -i ‘s/Click here/ /’ $FIL.txt;
sed -i ‘s/T-storms/ Thunder Storms/’ $FIL.txt

#Wind Direction
sed -i ‘s/ NW/ North West /;s/ NE/ North East /;s/ SW/ South West /;s/ SE/ South East /’ $FIL.txt;
sed -i ‘s/ NNW/ North North West /;s/ NNE/ North North East /’ $FIL.txt;
sed -i ‘s/ SSW/ South South West /;s/ SSE/ South South East /’ $FIL.txt;
sed -i ‘s/ WNW/ West North West /;s/ WSW/ West South West /’ $FIL.txt;
sed -i ‘s/ ESE/ East South East /;s/ ENE/ East North East /’ $FIL.txt;

cp $FIL.txt test;
sed -i ‘s/\[//;s/\]//’ $FIL.txt;

#Time zones
sed -i ‘s/PDT/Pacific Daylight Time/;s/PST/Pacific Standard Time/’ $FIL.txt;
sed -i ‘s/MDT/Mountain Daylight Time/;s/MST/Mountain Standard Time/’ $FIL.txt;
sed -i ‘s/CDT/Central Daylight Time/;s/CST/Central Standard Time/’ $FIL.txt;
sed -i ‘s/EDT/Eastern Daylight Time/;s/EST/Eastern Standard Time/’ $FIL.txt;

#Fix Haze
sed -i ‘s/haze/hayes/’ $FIL.txt;
sed -i ‘s/Haze/Hayes/’ $FIL.txt;

#Fix Wind
sed -i ‘s/Wind/Whend/’ $FIL.txt;
sed -i ‘s/wind/whend/’ $FIL.txt;

#Delete *
sed -i ‘s/\*/ /’ $FIL.txt;

#Deg F
sed -i ‘s/\°F/ \, /’ $FIL.txt;

#Inches
sed -i ‘s/ 1 in\. / 1 inch /’ $FIL.txt;
sed -i ‘s/ in\. / inches /’ $FIL.txt;

#NWS
sed -i ‘s/NWS/ National Weather Service /’ $FIL.txt;
sed -i ‘s/BestForecast/ Best Forecast /’ $FIL.txt;
sed -i ‘/’$day’/q’ $FIL.txt;
sed -i ‘/’$day’/d’ $FIL.txt;

### End of Files ###

#Generate and speak
/opt/swift/bin/swift -n $VOICE -p audio/channels=1,audio/encoding=ulaw -f $WX/$FIL.txt -o – | cat > $WX/$FIL.ulaw& asterisk -rx “rpt playback $NODE $WX/$FIL”&

Weather by Zipcode scripts*** ***Update: see above ***

As written – do *9790210    – for Current weather conditions in zip code 90210.

As written – do *9690210    – for weather forecast in zip code 90210.

—————————————————-

In extensions.conf add:

[wxzip]

exten => _XXXXX,1,System(/etc/asterisk/scripts/wxzip/Current ${EXTEN})

[wxzipf]

exten => _XXXXX,1,System(/etc/asterisk/scripts/wxzip/Forecast ${EXTEN})

[wxzipexf]

exten => _XXXXX,1,System(/etc/asterisk/scripts/wxzip/ExtForecast ${EXTEN})

—————————————————–

You will also need to install Cepstral TTS (Allison) or rewrite script for your TTS engine –