#!/bin/bash
#
# nixpunk 
# 07/14
#
# weather script using wunderground.com for scraping
#

usage() {
    echo "Usage: $(basename $0) <zipcode>"
}

if [[ $# != 1 ]]; then
    usage
    exit 1
fi

loc=$1
url='https://www.wunderground.com/cgi-bin/findweather/getForecast?query='
raw=$(curl -s $url$loc)
conditions=$(echo "$raw" | grep -w "now:" | awk -F \' 'NR==1{ print $2 }')

if [[ -z "$conditions" ]]; then
    echo "Error parsing conditions.  Check input zipcode."
    exit 2
fi

temp=$(echo "$raw" | grep "temp_now:" | awk -F \' '{ print $2 }' | awk '{ print $1 }')
degsym="°"

echo -en "${temp}${degsym}F"
echo ": $conditions"

