Today's Vote

Today’s Vote is an easy way to stay up to date with what Canada’s House of Commons is voting on each day. It automatically fetches and parses the votes, then presents the latest ten in a clean and easy-to-read format. They’re even automatically posted to Twitter and made available as JSON and RSS feeds so it’s easier to build things with the data.

Today’s Vote was written in Go and was my first project done so. It’s a simple worker that’s crosscompiled and run as a cron job on cheap shared hosting, so the setup is very minimal. It grabs the data, stores it in a Postgres database (almost unneccessary, although it affords some flexibility for new features) and renders the output to static HTML, RSS and JSON files. Tweets are sent using Buffer to prevent overwhelming timelines.

One problem that I ran into when making Today’s Vote was that the XML feed from the government was malformed (surprise!) and the description of each vote contained both the English and French version without any delimiter. After exploring a few different options to split the strings, I settled on translating the first word from English to French and then finding the last occurrence of that new word. This isn’t perfect, as an English sentence may not start with the same word in another language, but thankfully the way the government words vote descriptions is very consistent and there are few exceptions that need to be overridden.

Today’s Vote is a very linear program and at first almost all of the code (except for some API wrappers I made for Buffer and Bing Translate) was in the main function. I found refactoring later on to be pretty easy, and learning to use Go’s interfaces was very interesting. My only experience with compiled languages before Go was with very small C programs or large iOS apps in Objective-C. I found Go very enjoyable to work with especially because of it’s very short compile times and it’s enforcement of code style with gofmt, something I’d like to see more languages adopt.

In the future I’d like to work more with Go, especially to take advantage of it’s strong networking and concurrency features. You can see more and contribute to Today’s Vote on GitHub.