💾 Archived View for acidic.website › musings › first-gemini-app-us-weather.gmi captured on 2023-07-22 at 16:13:55. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2020-09-24)

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

US Hourly Weather Forecasts

Date: 2020-06-05

State: Done

TL;DR

Had some fun writing my first Gemini CGI app. The app is a Tcl script which requests an address. The address is looked up in the US Census Geolocator to grab latitude and longitude values, then this is looked up in the NWS Weather APIs to grab an hourly forecast.

US Hourly Weather Forecasts

Development with Tcl

I started learning Tcl to work on the Darwaza graphical Gemini browser, but found myself really enjoying the language. The syntax is lightweight and fun to use, and it's easy to roll your own control structures, like Scheme and other Lisps. I made a few commands that wrap Tcl script bodies and allow them to work in the context of an HTTP request with a parsed JSON body to help decrease boilerplate for handle error handling and other general HTTP request boilerplate. That said, the language just doesn't have a standard library with nearly as much polish as, say, Python. Documentation for packages can be sparse or even non-existent.

I couldn't find a library which handled URL decoding, so had to use a StackOverflow snippet to do the decoding.

URL Decoding Query Strings in Tcl

The default "rest" Tcl package which is supposed to make development of these sorts of things easy depends on a package known as tdom

tdom

which does not come with my local MacOS install (despite the brew package installing Tcl installing the "rest" package itself). I tried building tdom from source, but the build fails. I submitted a bug report to the Fossil bug tracker about the failing builds because I want to see Tcl succeed, but I have to admit, it puts a large burden on the developer. The main tdom site itself does not even appear in the first two pages of either DuckDuckGo or Google searches. While trying to parse timestamps returned by the NWS API, I thought I'd reach for datetime libraries as I've seen in Python, Java, Go, and Nim, but the ones in Tcl seem woefully underspecced. Nestled in tcllib (the Tcl standard library, or so I believe) is a package to parse ISO-8601 timestamps. The documentation looks like:

::clock::iso8601 Tcl library

and the semantics of Tcl "clock"s immediately convert the value into a Unix timestamp and drop any included timezone data. This affects the timezone with which the hourly weather forecast is returned. I tried to find a way to recover or hold onto the timezone information, but decided to just string parse the ISO-8601 format myself in a hacky way so I didn't spend any more time or what is trivial in most other language ecosystems. I may use Tcl more, but am thinking of switching back to Python for my other CGI scripts because of the sheer energy spent in doing basic work.

I have a lot of Tcl related thoughts, but I think that will have to wait for a dedicated Tcl post.