wttr.in is an awesome project allowing you
to fetch the current weather directly in your terminal via curl
. I use it to
put current weather data on my status bar in i3
, via i3status
’s file reading
feature. However, I quickly noticed an issue: the weather reports I received
almost never matched the actual weather in my location. Turns out, there was a
well known issue that had been outstanding for a few months: #492, Province
name is ignored while doing IP-based
geolocation. If you requested
weather data for an IP address geolocated to some country, province, city
, you
would get results back for country, city
. This looks harmless; what’s the
issue with dropping the province? For European users, this behavior was almost
never different. However, in the United States this would fail catastrophically:
province is synonymous with state. It doesn’t take much effort to find hundreds
of
instances
of this being a bad behavior in the United States.
From there, I set about fixing the issue. wttr.in
uses a few separate pieces
of architecture working together to produce your weather report. I cared about
lib/location.py
for fixing my issue, as the bad weather reports were occurring for IP based
requests. When I got there, the issue was plain: country and city were the only
values fetched from the geoip services in use! The rest were being thrown away.
Fixing this was more involved than adding the required values into the cached result and passing that along. At first glance, I thought it would be necessary to re-design the cache. However, every geoip service had all the information necessary to fill in the existing cache records, but sometimes in a different order. I eventually settled on a backwards-compatible method of re-ordering all the geoip data from each source into the same, consistent list format.
Lastly, my redesign provided the province out of _get_location(ip_addr)
! This
step was the easiest, because the existing weather reporting part of the
architecture already supported full country, province, city
weather reporting.
The real problem was that geolocated users were not supplying a province.
This was my first serious contribution to open source, and I’m quite proud of it.