shithub: json2awk

ref: f8d74ea182246209e30cb5e90e7697a5ad99a407
dir: /weather.rc/

View raw version
#!/bin/rc

fn formparams {
	urlp = $1'?'$2
	shift 2
	while(! ~ $#* 0){
		urlp = $urlp'&'$1
		shift
	}
	echo $urlp
}

fn pull {
	purl = $1
	shift
	hget $purl | jawk $*
}

geourl = 'https://geocoding.geo.census.gov/geocoder/locations/address'
street = '0000+REDACTED+AVE'
zip = 99999

geourl = `{formparams $geourl \
	'street='$street \
	'zip='$zip \
	'format=json' \
	'benchmark=Public_AR_Current'
}

# get our coordinates
xy = `{pull $geourl '
	print json["result", "addressMatches", 0, "coordinates", "x"]
	print json["result", "addressMatches", 0, "coordinates", "y"]
'}

# get the forecast url for our location
url = https://api.weather.gov/points/$xy(2)^,$xy(1)
forecasturl = `{pull $url 'print json["properties", "forecast"]'}

# print the forecast
pull $forecasturl '
	for(i = 0;; i++){
		when = json["properties", "periods", i, "name"]
		if(when == "")
			break;
		print when
		print "\t" json["properties", "periods", i, "detailedForecast"]
	}
' | fmt