Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
5
midnightlightning avatar

Doing a triple-lookup for every run ("human-friendly" location name to lat/lng, lat/lng to list of stations, individual station data) is a decent amount of overhead, and more possibilities for an individual request to fail.

I'd recommend using val.town's SQLite feature to create a table matching LOCATION values to "openAQLocation IDs". Thus, if the location never changes for a user (likely), the first two queries can be skipped most runs.

stevekrouse avatar

Great idea! What do you think of this implementation? https://www.val.town/pulls/bf6db21e-1d03-11ef-a060-cab58f78796a

midnightlightning avatar

That looks wonderful! Since your example "location" value has spaces in it, likely most users will follow suit. That means your blob cache key will have underscores for the first part of the key, and then spaces for the last half. That's not too big a deal, but you may want to do some light sanitizing on the user's input to make it consistent (all lower-case, all whitespaces to underscores, all non-alphanumeric characters removed) and a little more human-friendly if a user uses the "admin" tools to browse their blob objects.

stevekrouse avatar

great idea!

stevekrouse avatar

done and merged :)

Updated: May 30, 2024