Get the Current Weather Conditions for a U.S. Location from weather.gov
Here's how I'm getting current weather conditions/observations from the U.S. weather.gov API:
- Find the lat/long coordinates from the location in decimal values (i.e. not with minute and seconds)
-
Query this URL:
https://api.weather.gov/points/LAT,LONG
-
In the data that comes down, pull the value from
.properties.observationStations
To get a URL like:
https://api.weather.gov/gridpoints/BMX/81,35/stations
-
From the response at that URL pull the first URL at:
.observationStations[0]
To get a URL like:
https://api.weather.gov/stations/KMGM
-
Add
observations/latestto the URL like this to get the latest observations:https://api.weather.gov/stations/KMGM/observations/latest
Endnotes
You have to send a `User-Agent` header along with any requests to the API. Otherwise, you'll get a 403 Forbidden. The value for the header can be anything, but they ask you do something that makes yours unique. They also ask that you put your email in the header field so they can contact you about resource usage if necessary. That decisions in on you.
You don't need an API key (just the `User-Agent` header)
References
Just basic API exploration
Another tool to look at. It requires an API key though.
Saw this when I was looking around. Haven't checked it out yet. Keeping here for reference.
Fun little command line accessible weather report.