💾 Archived View for jsreed5.org › log › 2023 › 202306 › 20230619-announcement-weather-cgi-fixes.gmi captured on 2024-05-26 at 15:00:25. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-07-10)

-=-=-=-=-=-=-

Announcement: Weather CGI Fixes

2023-06-19

---

In the early days of my capsule I implemented a weather forecast CGI. A visitor can enter a five-digit US ZIP code, and the CGI will present a one-week weather forecast from the National Weather Service. That CGI is still online today.

The original script was written in Bash, but in July of 2022 I converted all my CGI content to Python. In preparation for that change, I compiled a database with a list of ZIP codes, their corresponding cities and states, and the NWS weather stations and grid numbers needed to get the ZIP's forecast via API. This required me to first find a source that gave the latitude and longitudes of each ZIP code, then querying the API with the list of coordinates to get the stations.

Even when I implemented the database, I knew I was missing ZIP codes. The source itself appeared to be imcomplete, and several of the existing ZIP codes had coordinates that the NWS didn't recognize. However, it was the best set I could find that was completely free, so I went into production with it.

In April I discovered a flaw in my original database creation script: the ZIPs were stored in the database as integers, and any ZIP code that had leading zeros had not been loaded. This included all the ZIP codes in the states of Connecticut, Maine, Massachusetts, New Hampshire, New Jersey, Rhode Island, and Vermont, as well as the territory of Puerto Rico. Of course their absense meant that I didn't have any weather station information for them, so I couldn't easily re-add them.

I finally got around to solving the problem yesterday. This time I used SimpleMaps as my coordinate source, which is not completely free but is far better quality. At time of writing, their data is verified correct and current up to 2023-02-13. After scraping the NWS API overnight, I compiled all the information into an updated database this morning, and the new database went live a few hours ago.

Visitors to the service will see no change, except a required attribution to SimpleMaps at the bottom of the page. The service does not use their coordinate data directly, but it does use the city and state names listed in their data, and the coordinate information was used to populate the static database.

I apologize if anyone was unable to use the service for their ZIP code. I hope you find it useful!

---

Up One Level

Home

[Last updated: 2023-06-19]