Yet Another Weather Indicator

3 minute read Published:

A simple GTK weather indicator written in Go because why not.

Recently I started using Openbox as my WM again (after a long time with KDE, the nostalgia hit me). After I had everything working as I wanted to, I noticed the lack of a weather indicator in my systray.

Usually, the desktop environments I have used (Gnome, KDE, Mate) have some sort of applet for this included and I really never bothered (when I was using Openbox before, I had some hacky script that would display the weather in my tint2, but I can’t find it anymore). So I came across go-gtk and felt compeled to write my own tiny indicator.

The go-gtk package is really nice, even tough it is said to cover 47% of all what GTK has to offer, it is still amazing. The plan was to find a weather provider with a free API and as a bonus, I wanted a provider which could also give me weather icons for each kind of scenario.

I started by forking go-wunderground which is a Go package to interact with the Weather Underground API and modifying it a little bit to include icon support, something that the original author didn’t included. You can take a look at my fork here.

It worked well and all but honestly, I didn’t liked the icons on my dark tint2 bar for some reason. I went back to search for another provider and came across Weatherbit which allows 75 free API requests per hour, more than enough for my needs. Looking at the provided icons, I decided to give it a try. There was no available Go package for Weatherbit API so I quickly wrote one after testing a lot locally with curl and reading their documentation (not very feature rich, very simple and lacking some features that their API provided, which I might improve in the future).

All I had to do now was to write the actual indicator. I fired up Visual Studio Code (amazing Golang support, really) and started writting what became my own simplistic (very) weather indicator. As of now, it accepts your country, city and API key as parameters and updates the weather every 1 hour. I plan to add further customization and more features but the essential goal was reached here, a simple icon that gives me some information about the weather (when you hover your mouse over it).

You can download it via go get:

$ go get -u "github.com/guitmz/go-weather-indicator"

And the usage is as simple as:

$ go-weather-indicator --city Berlin --country Germany --key API_KEY

It looks like this in my tint2 bar:

For now I am happy with it but I really wanted to make this cross platform using the systray and ui Go packages. Technically, the application runs fine on Windows and macOS if GTK is installed but I tried and while it works, visually it doesn’t look very polished.

Here’s what my first try at this looks on macOS Sierra:

Not the best looking I know but it’s just a test code for now, I will update the repository once I have something nice working.

That’s it, any feedback is appreciated :)

comments powered by Disqus