I am wanting to retrieve the current temperature at my location from a Linux shell using only public APIs; nothing that requires a subscription or creating credentials with an API provider.
The solution requires you to have these tools installed to your Linux OS:
TL;DR, here's the final command-line:
curl -s -L "$(curl -s -L "https://api.weather.gov/points/$(curl -s -L "https://nominatim.openstreetmap.org/search.php?q=$(curl -s -L ipinfo.io | jq -r '"\(.city),\(.region)"')&polygon_geojson=1&format=jsonv2" | jq -r '"\(.[0].lat),\(.[0].lon)"')" | jq -r '.properties.forecastHourly')" | jq -r '.properties.periods[0].temperature'
Breaking it down:
(The ... represents the command from the previous step.)
curl -s -L ipinfo.io
... | jq -r '"\(.city),\(.region)"'
curl -s -L "https://nominatim.openstreetmap.org/search.php?q=$(...)&polygon_geojson=1&format=jsonv2"
... | jq -r '"\(.[0].lat),\(.[0].lon)"'
curl -s -L "https://api.weather.gov/points/$(...)"
... | jq -r '.properties.forecastHourly'
curl -s -L "$(...)"
... | jq -r '.properties.periods[0].temperature'
Easy as that.
P.S.
As pointed out by David, the call to ipinfo.io actually does return the latitude and longitude, so the OpenStreetMap portion of the command can be left out entirely, e.g.:
curl -s -L "$(curl -s -L "https://api.weather.gov/points/$(curl -s -L ipinfo.io | jq -r '"(.loc)"')" | jq -r '.properties.forecastHourly')" | jq -r '.properties.periods[0].temperature'