Anonymous Anonymous - 2 months ago
142 0

No description

Bash

weatherunderground - condition

#!/bin/bash

# jsonval credit: https://gist.github.com/cjus/1047794
jsonval () {
temp=`echo $haystack | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $needle`
        echo ${temp##*|}
}

dev_key='xxxxxxxxxxxx'
city='Enschede'
state='OV'
red=$(tput setaf 1)
textreset=$(tput sgr0)

haystack=$(curl -Ls -X GET http://api.wunderground.com/api/$dev_key/conditions/q/$state/$city.json)

needle='weather'
current_condition=$(jsonval $needle $haystack)

echo -e $current_condition