Hacker News new | ask | show | jobs
by davchana 1257 days ago
I usually use forecase.weather.gov They provide a nice textual weather page, with English, for next 7 or 8 days [1]. But it is tiring to open 3 or 4 bookmarks, so I thought to consume that as json & make a single page html app with ajax requests. Its still in progress, I spent few minutes yesterday. The surprising thing was (I was ready to fetch the html text & parse it, difficult), I simply changed one parameter to JSON & I got json [2]. I didn't find any easy to find documentation about json endpoint. My plan is to have city abbreviations on top in horizontal menu, then each click fetches json, puts it into div below.

1. https://forecast.weather.gov/MapClick.php?lat=37.78&lon=-122...

2. https://forecast.weather.gov/MapClick.php?lat=37.98&lon=-120...

1 comments

That is cool the web front end exposes itself as JSON as well, good tip.

FWIW, they also have a pretty decent API. Its based around zones though, which you'd need to look up. So from that lat and lon, you'd get the zone from:

https://api.weather.gov/points/37.7827,-120.38

Using the zone information, you can get to a forecast:

https://api.weather.gov/gridpoints/STO/72,24/forecast

If you're wanting the current observations, you'd pick a station for that grid such as MOUC1 and go to its observations/latest endpoint:

https://api.weather.gov/stations/MOUC1/observations/latest

The API is in a JSON-LD format so its got a lot of links to related topics in the actual JSON payload. Looking at the JSON can make it somewhat easy to feel out what you need. The documentation is here:

https://www.weather.gov/documentation/services-web-api

Thanks, on that day I already was playing with the api.

Initially I had few bookmarks saved on my android home screen, for each city I was interested in weather forecast of. But soon there were total 4 cities; & their text size is too small, need to zoom. I slurped their json api & wrote this:

https://spa.bydav.in/weather/

You need to add URL for each city you want to see weather, in Settings. All that data is saved in your device local storage. No funny trackers or home phone.

You can also paste the following json in Settings > Text Area > Click Import JSON:

  [
    {
      "abb": "STK",
      "full": "Stockton",
      "url": "https://forecast.weather.gov/MapClick.php?lat=37.95&lon=-121.29&unit=0&lg=english&FcstType=json&TextType=1"
    },
    {
      "abb": "SFO",
      "full": "San Francisco",
      "url": "https://forecast.weather.gov/MapClick.php?lat=37.7771&lon=-122.4197&unit=0&lg=english&FcstType=json&TextType=1"
    }
  ]