Skip to content

Instantly share code, notes, and snippets.

@MaxwellDPS
Created March 29, 2025 03:10
Show Gist options
  • Select an option

  • Save MaxwellDPS/1b7e35fb8f8eb99449cde918e2138167 to your computer and use it in GitHub Desktop.

Select an option

Save MaxwellDPS/1b7e35fb8f8eb99449cde918e2138167 to your computer and use it in GitHub Desktop.
Bash is the scenic route
#!/bin/bash
VT1="AF,Ashfall
AS,Air Stagnation
AV,Avalanche
BH,Beach Hazard
BS,Blowing Snow
BW,Brisk Wind
BZ,Blizzard
CF,Coastal Flood
DS,Dust Storm
DU,Blowing Dust
EC,Extreme Cold
EH,Excessive Heat
EW,Extreme Wind
FA,Areal Flood
FF,Flash Flood
FG,Dense Fog
FL,Flood
FR,Frost
FW,Fire Weather
FZ,Freeze
GL,Gale
HF,Hurricane Force Wind
HI,Inland Hurricane Wind
HS,Heavy Snow
HT,Heat
HU,Hurricane
HW,High Wind
HY,Hydrologic
HZ,Hard Freeze
IP,Sleet
IS,Ice Storm
LB,Lake Effect Snow and Blowing Snow
LE,Lake Effect Snow
LO,Low Water
LS,Lakeshore Flood
LW,Lake Wind
MA,Marine
MF,Marine Dense Fog
MH,Marine Ashfall
MS,Marine Dense Smoke
RB,Small Craft for Rough Bar
RP,Rip Currents
SB,Snow And Blowing Snow
SC,Small Craft
SE,Hazardous Seas
SI,Small Craft for Winds
SM,Smoke
SN,Snow
SQ,Snow Squall
SR,Storm
SS,Storm Surge
SU,High Surf
SV,Severe Thunderstorm
SW,Small Craft for Hazardous Seas
TI,Inland Tropical Storm Wind
TO,Tornado
TR,Tropical Storm
TS,Tsunami
TY,Typhoon
UP,Freezing Spray
WC,Wind Chill
WI,Wind
WS,Winter Storm
WW,Winter Weather
ZF,Freezing Fog
ZR,Freezing Rain"
VT2="W,Warning
F,Forecast
A,Watch
O,Outlook
Y,Advisory
N,Synopsis
S,Statement"
VT3="NEW,New
CON,Continued
EXT,Changed in Time
EXA,Changed in Area
EXB,Changed in Time and Area
CAN,Cancelled
UPG,Upgraded
EXP,Expired
COR,Corrected
ROU,Routine"
CLR='\e[0m'
# Winter WX
WSA='\e[40;38;5;141m'
WSW='\e[40;38;5;51m'
WWY='\e[40;38;5;105m'
# Blizzard WX
BSA="\e[40;38;5;99m"
BSW="\e[40;38;5;201m"
# EXTREME
EXTRBG="\e[48;5;201m\e[1;5;255m"
EXTR="\e[40;38;5;201m"
# STD SVR WX
WATCH="\e[40;38;5;226m"
WARNINGBG="\e[48;5;196m\e[1;5;255m"
WARNING="\e[40;38;5;196m"
FLOOD="\e[40;38;5;46m"
# OTHER WX
LowALERT="\e[40;38;5;11m"
# FMAT
TIME="\e[40;38;5;46m"
LOC="\e[40;38;5;255m"
us=0
STATE=0
s1=0
zone="SDZ069"
for ((i=1;i<=$#;i++));
do
if [ ${!i} = "-a" ]
then ((i++))
us=1;
elif [ ${!i} = "--state" ];
then ((i++))
STATE=${!i};
s1=1;
elif [ ${!i} = "-c" ];
then ((i++))
zone=${!i};
elif [ ${!i} = "-z" ];
then ((i++))
zone=${!i};
fi
done;
if [ $us == 1 ]
then
ralerts=$(wget -q -O - "https://alerts.weather.gov/cap/us.php?x=0")
elif [ $s1 == 1 ]
then
ralerts=$(wget -q -O - "https://alerts.weather.gov/cap/$STATE.php?x=0")
else
ralerts=$(wget -q -O - "http://alerts.weather.gov/cap/wwaatmget.php?x=$zone&y=0" )
fi
# No alerts - if a cache exists, delete it.
if [ $(echo "$ralerts" | grep -c "There are no active watches") -eq "1" ]; then
exit 0
fi
# /O.NEW.KFSD.WW.Y.0029.191113T1000Z-191113T1600Z/
vtecs=$(echo "$ralerts" | grep -A1 -P 'VTEC' | sed -e '1,1d' | sed -e 's/<[^>]*>//g' | sed '/VTEC/d' | sed '/^$/d' | sed '/--/d')
#Base=$(echo "$ralerts" | grep -A10 -P 'cap:areaDesc' | sed -e '1,1d' | sed '/cap:polygon/d' | sed -e 's/<[^>]*>//g' | sed '/VTEC/d' | sed '/FIPS6/,+1 d' | sed '/UGC/,+1 d' | sed '/^$/d' )
#vtecs=""
while read -r vtec2; do
vtec=$(echo "$vtec2" | tail -c +2 | head -c -2 |tr "." "\n" )
AlertOp=$(echo "$vtec"| sed -n 1p )
AlertStatus=$(echo "$vtec"| sed -n 2p )
AlertWFO=$(echo "$vtec"| sed -n 3p )
Alert=$(echo "$vtec"| sed -n 4p )
AlertType=$(echo "$vtec"| sed -n 5p )
AlertNum=$(echo "$vtec"| sed -n 6p )
stz=$(echo "$vtec"| sed -n 7p | tr "-" "\n" | tr "Z" "\n"| sed -n 1p)
etz=$(echo "$vtec"| sed -n 7p | tr "-" "\n" | tr "Z" "\n"| sed -n 3p)
StartTime=$(date -d "$stz +1 hour" +"%a %b %d %I:%M:%S %p CST %Y" -u 2>&1)
EndTime=$(date -d "$etz +1 hour" +"%a %b %d %I:%M:%S %p CST %Y" -u 2>&1)
while IFS="" read -r p
do
a=$(echo "$p" | tr "," "\n" | sed -n 1p)
b=$(echo "$p" | tr "," "\n" | sed -n 2p)
if [ "$a" == "$Alert" ]; then
AlertName=$(echo $b)
break
fi
done <<< "$VT1"
while IFS="" read -r p
do
aa=$(echo "$p" | tr "," "\n" | sed -n 1p)
bb=$(echo "$p" | tr "," "\n" | sed -n 2p)
if [ "$aa" == "$AlertType" ]; then
AlertTName=$(echo $bb)
break
fi
done <<< "$VT2"
while IFS="" read -r p
do
a=$(echo "$p" | tr "," "\n" | sed -n 1p)
b=$(echo "$p" | tr "," "\n" | sed -n 2p)
if [ "$a" == "$AlertStatus" ]; then
AlertS=$(echo $b)
break
fi
done <<< "$VT3"
if [ "${1}" == "SDZ069" ]; then
location=$(echo "Yanton County, SD")
else
location=""
fi
if [ $(echo "$AlertName" | grep -c "Winter") -eq "1" ]; then
if [ $(echo "$AlertTName" | grep -c "Watch") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${WSA}*${CLR} There is a ${WSA}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${WSA}*${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
elif [ $(echo "$AlertTName" | grep -c "Warning") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${WSW}**${CLR} There is a ${WSW}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${WSW}**${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
elif [ $(echo "$AlertTName" | grep -c "Advisory") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "There is a ${WWY}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
else
echo "------------------------------------------------------------------------------------------------------------"
echo -e "There is a ${LowALERT}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
fi
elif [ $(echo "$AlertName" | grep -c "Blizzard") -eq "1" ]; then
if [ $(echo "$AlertTName" | grep -c "Watch") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${BZA}*${CLR} There is a ${BZA}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${BZA}*${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
elif [ $(echo "$AlertTName" | grep -c "Warning") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${BSW}**${CLR} There is a ${BSW}$AlertName $AlertTName\e[0m ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${BSW}**${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
else
echo "------------------------------------------------------------------------------------------------------------"
echo -e "There is a ${LowALERT}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
fi
else
if [ $(echo "$AlertTName" | grep -c "Watch") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${WATCH}**${CLR} There is a ${WATCH}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${WATCH}**${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
elif [ $(echo "$AlertTName" | grep -c "Warning") -eq "1" ]; then
if [ $(echo "$AlertName" | egrep -ci "TORNADO|DUST|EXTREME WIND|TSUNAMI|SQUALL") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${EXTR}**${CLR} There is a ${EXTRBG}$AlertName $AlertTName\e[0m${CLR} In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${EXTR}**${CLR}"
echo -e "${EXTRBG}**** THIS IS A LIFE THREATING SITUATION TAKE COVER NOW! ****${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
elif [ $(echo "$AlertName" | egrep -ci "FLOOD") -eq "1" ]; then
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${FLOOD}**\e[0m${CLR} There is a ${FLOOD}$AlertName $AlertTName\e[0m${CLR} In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${FLOOD}**${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
else
echo "------------------------------------------------------------------------------------------------------------"
echo -e "${WARNING}**\e[0m${CLR} There is a ${WARNINGBG}$AlertName $AlertTName\e[0m${CLR} In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR} ${WARNING}**${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
fi
else
echo "------------------------------------------------------------------------------------------------------------"
echo -e "There is a ${LowALERT}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR}"
echo "------------------------------------------------------------------------------------------------------------"
fi
fi
#echo -e "A $AlertS ${WSA}$AlertName $AlertTName ${CLR}Was Issued At ${TIME}$StartTime ${CLR}Until ${LOC}$EndTime ${CLR}by $AlertWFO"
#echo -e "There is a ${WSA}$AlertName $AlertTName ${CLR}In Effect Until ${TIME}$EndTime ${CLR}IN ${LOC}$location${CLR}"
done <<< "$vtecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment