3 ms·
Yes, I am using a handful of different APIs. My full terminal weather setup deserves its own blog post... but until then, here are some zsh snippets, scripts, a
by aftbit 4y ago
Yes, I am using a handful of different APIs. My full terminal weather setup deserves its own blog post... but until then, here are some zsh snippets, scripts, and curls to get you started.
Rough weather information for next days and hours:
# Find zone with curl https://api.weather.gov/points/40.5878,-103.0694
ZONE=${ZONE:-CAZ508}
echo "Forecast for zone $ZONE"
curl -s -A MyWeather/1.0 https://api.weather.gov/zones/forecast/$ZONE/forecast \
| jq -r '.properties.periods[] | [.name, .detailedForecast] | join("\t")' \
| column -t -s $'\t'
# Find grid with same curl
GRID=${GRID:-MTR/93,131}
echo ""
echo "Next 24 hours for grid $GRID"
curl -s -A MyWeather/1.0 https://api.weather.gov/gridpoints/$GRID/forecast/hourly \
| jq --arg date $(date -Is) -r '.properties.periods[] | select(.startTime >= $date) | [(.startTime), ((.temperature|tostring) + " " + .temperatureUnit), (.windSpeed + " @ " + .windDirection), .shortForecast] | join("\t")' \
| column -t -s $'\t' \
| head -n 24
Weather discussion script (also using regexps to parse HTML):
https://gist.github.com/lachesis/6c7e5020b112fe8d7bcc83d99dae1f5f https://gist.github.com/lachesis/6c7e5020b112fe8d7bcc83d99da...
Some docs on the "DWML rest API" that provides the dewpoint/humidity forecasts that I mentioned earlier:
https://graphical.weather.gov/xml/rest.php https://graphical.weather.gov/xml/rest.php
https://graphical.weather.gov/xml/DWMLgen/schema/latest_DWML.txt https://graphical.weather.gov/xml/DWMLgen/schema/latest_DWML...
https://graphical.weather.gov/xml/docs/elementInputNames.php https://graphical.weather.gov/xml/docs/elementInputNames.php
Here's the script I use to access that API but it is still under active development and is pretty tailored for my situation. Please forgive jankiness. Give it LAT / LNG environment variables.
https://gist.github.com/lachesis/480a1811c75999205cb17a119b49ef94 https://gist.github.com/lachesis/480a1811c75999205cb17a119b4...
Bonus points, for CA fire season, here's a script that shows PM2.5 for AirNow stations near a certain LAT/LNG:
https://gist.github.com/lachesis/a47212c848430e16e7d1ec6d85515fc3 https://gist.github.com/lachesis/a47212c848430e16e7d1ec6d855...