~evn/blog/

tilde-ing about

Canadian Weather Forecasts on my Tildepage

January 13, 2019 — ~evn

I wrote a little script to parse Environment Canada's weather forecasts for Squamish Canada and publish a summary to my tilde.team site.

Check it out!

I wrote it in Lua because I'd like to learn more about it; and its reputation for being lighweight makes it seem like a good fit for tildeverse projects.

Environment Canada publishes weather forecasts in RSS feeds. Links to these feeds can be found on the forecast page for any Canadian city or town, under the "Follow" section.

The script parses out just a short text description of the current weather conditions and the forecasts for the next six days. It throws it all in a simple HTML table and adds some little three-character ASCII icons representing the weather. For example, if the word 'snow' occurs in the forecast there will be a "*" next to that forecast. (The asterisks represent snowflakes.)

I wrote it in Lua 5.1. It requires the luasec library to retrieve documents from the web over HTTPS and xml2lua to parse the RSS feed's XML. Both of these can be installed using Luarocks. See the tilde.team wiki for details on setting up Lua on tilde.team.

It uses the dracula.css stylesheet from tilde.team.

It should be really easy to adapt to different Canadian cities. Just change the "feedUrl" variable to the RSS feed for your local forecast and change the "outputPath" variable so that it spits the HTML output to somewhere in your public_html folder.

Adapting it to read forecast data from other sources would be a little more work, but still should be pretty easy. If you think this is cool hack away and have fun!

Here's the source.

tags: weather, forecast, lua