HamVOIP Weather Script

Today:

# script written by NA7Q
# Dec 27 2022
# This script downloads the weather forecast from the NWS
# 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 * * * /tmp/NWS/Forecast.sh

mkdir /tmp/NWS

#Astoria
lynx --dump "https://forecast.weather.gov/MapClick.php?lat=46.1898&lon=-123.8339&FcstType=text&TextType=2" > /tmp/NWS/today.txt

DATE="$(date +%A)"

if grep -q 'Today: ' /tmp/NWS/today.txt; then
	sed -i '100,200d' /tmp/NWS/today.txt
	sed -i "/n/{H;$!d};x;/Today: /!d" /tmp/NWS/today.txt
		elif 
		grep -q 'This Afternoon: ' /tmp/NWS/today.txt; then
			sed -i '100,200d' /tmp/NWS/today.txt
			sed -i "/n/{H;$!d};x;/This Afternoon: /!d" /tmp/NWS/today.txt
			elif
				grep -q 'Tonight: ' /tmp/NWS/today.txt; then
				sed -i '100,200d' /tmp/NWS/today.txt
				sed "/n/{H;$!d};x;/Tonight: /!d" /tmp/NWS/today.txt
				else
					grep -q 'Overnight: ' /tmp/NWS/today.txt
					sed -i '100,200d' /tmp/NWS/today.txt
					sed "/n/{H;$!d};x;/Overnight: /!d" /tmp/NWS/today.txt
fi
	
	
# tts_audio doesn't say winds correctly. Make her say "wend" instead. Change mph to miles per hour. Remove new lines to fix audio pauses.	
sed -i 's/   //g' /tmp/NWS/today.txt
sed -i 's/wind/wend/g' /tmp/NWS/today.txt
sed -i 's/mph/miles per hour/g' /tmp/NWS/today.txt
sed -i ':a;$!{N;s/\n/ /;ba;}' /tmp/NWS/today.txt


# convert the file to a ul file using tts_audio.sh
tts_audio.sh /tmp/NWS/today.txt

# play the resulting file on the air by calling asterisk
# for 46891 ... insert your own node number
asterisk -rx "rpt localplay NODENUMBER /tmp/NWS/today"

# remove the temporary files after debugging
rm /tmp/NWS/today.txt

Tomorrow:

mkdir /tmp/NWS

#Astoria
lynx --dump "https://forecast.weather.gov/MapClick.php?lat=46.1898&lon=-123.8339&FcstType=text&TextType=2" > /tmp/NWS/tomorrow.txt

DATE="$(date -d tomorrow +'%A')"


# take the header out by removing lines 2 through 4.
sed -i '100,200d' /tmp/NWS/tomorrow.txt
sed -i "/n/{H;$!d};x;/$DATE:/!d" /tmp/NWS/tomorrow.txt

# tts_audio doesn't say winds correctly. Make her say "wend" instead. Change mph to miles per hour. Remove new lines to fix audio pauses.
sed -i 's/   //g' /tmp/NWS/tomorrow.txt
sed -i 's/wind/wend/g' /tmp/NWS/tomorrow.txt
sed -i 's/mph/miles per hour/g' /tmp/NWS/tomorrow.txt
sed -i ':a;$!{N;s/\n/ /;ba;}' /tmp/NWS/tomorrow.txt



# convert the file to a ul file using tts_audio.sh
tts_audio.sh /tmp/NWS/tomorrow.txt

# play the resulting file on the air by calling asterisk
# for 46891 ... insert your own node number
asterisk -rx "rpt localplay NODENUMBER /tmp/NWS/tomorrow"

# remove the temporary files after debugging
rm /tmp/NWS/tomorrow.txt

Day After Tomorrow:

mkdir /tmp/NWS

#Astoria
lynx --dump "https://forecast.weather.gov/MapClick.php?lat=46.1898&lon=-123.8339&FcstType=text&TextType=2" > /tmp/NWS/tomorrowafter.txt

DATE="$(date -d "2 days" '+%A')"


# take the header out by removing lines 2 through 4.
sed -i '100,200d' /tmp/NWS/tomorrowafter.txt
sed -i "/n/{H;$!d};x;/$DATE:/!d" /tmp/NWS/tomorrowafter.txt

# tts_audio doesn't say winds correctly. Make her say "wend" instead. Change mph to miles per hour. Remove new lines to fix audio pauses.
sed -i 's/   //g' /tmp/NWS/tomorrowafter.txt
sed -i 's/wind/wend/g' /tmp/NWS/tomorrowafter.txt
sed -i 's/mph/miles per hour/g' /tmp/NWS/tomorrowafter.txt
sed -i ':a;$!{N;s/\n/ /;ba;}' /tmp/NWS/tomorrowafter.txt


# convert the file to a ul file using tts_audio.sh
tts_audio.sh /tmp/NWS/tomorrowafter.txt

# play the resulting file on the air by calling asterisk
# for 46891 ... insert your own node number
asterisk -rx "rpt localplay NODENUMBER /tmp/NWS/tomorrowafter"

# remove the temporary files after debugging
rm /tmp/NWS/tomorrowafter.txt