Sunday, December 16, 2018

HamVOIP AllStarLink node weather script

I wrote this script early in the year, and it works rather well.
The script uses the national weather service to get a text transcription of the weather forecast.
It re-formats the text taking out the header and footer.
It then uses a text to speech translator to create a .ul file which can be read over the air by Asterisk.
(the Linux computer must have tts_audio installed)
Another crontab deletes the .ul file at midnight.

This is implemented on a hamvoip node on a Raspberry Pi.
It can be triggered by DTMF tones or on a time schedule.

The script is written below

73

N3FIX

----------------------------------------------
# script written by N3FIX
# date 2018-JAN-13
# this script downloads the weather forecast
# strips the header and footer
# converts it from a txt file to a .ul file
# and plays the .ul file on the air.
# play the forecast at 8:00 am and edit the crontab
# crontab -e
# 00 8 * * * /etc/asterisk/local/Forecast.sh

# use the lynx dump command to get the current weather forecast
# determine zone from alerts.weather.gov
# zone is PAZ065
lynx --dump "http://forecast.weather.gov/MapClick.php?zoneid=PAZ065&FcstType=text&TextType=2" > Forecast.txt

# take the header out by removing lines 2 through 4.
sed '2,4d' /etc/asterisk/local/Forecast.txt > /etc/asterisk/local/Forecast1.txt

# take the footer out by listing the file backwards with tac and taking out lines 1 to 10.
tac /etc/asterisk/local/Forecast1.txt | sed '1,10d' | tac > /etc/asterisk/local/Forecast.txt

# remove all the underscores from the file
sed 's/_//g' /etc/asterisk/local/Forecast.txt > /etc/asterisk/local/Forecast1.txt

# tts_audio doesn't say winds correctly. Make her say "wend" instead.
sed 's/winds/wend/g' /etc/asterisk/local/Forecast1.txt > /etc/asterisk/local/Forecast.txt

# convert the file to a ul file using tts_audio.sh
tts_audio.sh /etc/asterisk/local/Forecast.txt

# play the resulting file on the air by calling asterisk
# for 46891 ... insert your own node number
asterisk -rx "rpt localplay 46891 /etc/asterisk/local/Forecast"

# remove the temporary files after debugging
rm /etc/asterisk/local/Forecast1.txt
rm /etc/asterisk/local/Forecast.txt
------------------------------------------------

No comments:

Post a Comment