#!/usr/bin/bash ruser=$1 rnode=$2 IFS=" " ; read -r -a cmd_parts <<< "$3" rcmd="${cmd_parts[0]}" ZIP_CSV="/usr/local/nje/infothot/zipcodes.csv" case "$rcmd" in wea*|WEA*|FORE*|fore*) LAT="${cmd_parts[1]}" LONG="${cmd_parts[2]}" if [[ -z "$LONG" ]]; then zipcode=$(printf "%05d" "$LAT") raw_coords=$(jq -r --arg z "$zipcode" '.[$z] | join(" ")' "$ZIP_CSV") if [[ "$raw_coords" != "null" ]] && [[ -n "$raw_coords" ]]; then read -r LAT LONG <<< $(echo "$raw_coords" | awk '{printf "%+.2f %+.2f", $1, $2}') else /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "Error: Zip code $zipcode not found." exit 1 fi fi forecast_url="$(curl -s -A "PUBVM.ORG NWSNJE" "https://api.weather.gov/points/$LAT,$LONG" | jq -r '.properties.forecast')" if [ "$forecast_url" != "null" ]; then /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "Punching forecast for [$LAT,$LONG] to your reader." out_file="/tmp/weather_${ruser}_$$.pun" echo " +--------------------------------------------------------------------------+" >> "$out_file" echo " NWS Forecast for (${LAT}, ${LONG}) gathered $(date '+%d %B %Y')" | awk '{printf " | %-66s| \n", $0}' >> "$out_file" echo " +--------------------------------------------------------------------------+" >> "$out_file" echo " Using: ${forecast_url} " | awk '{printf " | %-73s|\n", $0}' >> "$out_file" echo " +--------------------------------------------------------------------------+" >> "$out_file" curl -s -A "PUBVM.ORG NWSNJE" "${forecast_url}" | \ jq -r '.properties.periods[0,1,2,3] | "\(.name | ascii_upcase) (\(.temperature)\(.temperatureUnit)): \(.detailedForecast)\n"' | \ fmt -w 73 | \ awk '{printf " | %-73s|\n", $0}' >> "$out_file" echo " +-----------------------------END OF LINE----------------------------------+" >> "$out_file" /usr/local/nje/bin/sf $ruser@$rnode -u infothot -fn FORECAST "$(date +%Y%m%d)" "$out_file" rm "$out_file" else /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "Error: Invalid coordinates [$LAT, $LONG]." fi         ;; noaa*|NOAA*) REQ="${cmd_parts[1],,}" fname=$(echo "${cmd_parts[1]}" | tr '[:lower:]' '[:upper:]' | tr -cd '[:alnum:]' | cut -c 1-8) out_file="/tmp/${fname}_${ruser}_$$.pun" wget "https://services.swpc.noaa.gov/text/${REQ}.txt" -O "$out_file" if [ $? -eq 0 ]; then /usr/local/nje/bin/sf $ruser@$rnode -u infothot -fn "${fname}" NOAASWPC "$out_file" else /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "'${REQ}' not found on NOAA server." fi rm "$out_file" ;; *) /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "'$rcmd' not found" /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "Current commands: " /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "weather (zip code) [LAT] [LONG]: Weather.gov report use zip code OR lat long" /usr/local/nje/bin/tell -u infothot -m $ruser@$rnode "noaa (request): NOAA Space Weather (weekly, srs, discussion, 3-day-forecast)" ;; esac