Update (May 7, 2016): Many thanks to kind reader @chogc who asked about the metric option to display temperature in Celsius. That feature has been corrected. I also implemented a workaround of a Yahoo! weather bug in which the sunset time string drops the leading zero for the minutes in some locations. Version 1.1 incorporating these fixes can be found here.
I’m a long-time GeekTool user, which I use to display various pieces of information on my Mac desktop. One of my favorite displays is current weather information. A few years ago after browsing on the Internet for various weather geeklets and scripts, I settled on one created by Thomas Upton written in Python that used Yahoo! weather for displaying current conditions, called weather.py:
I also used two additional scripts from other sources for displaying a current weather image icon obtained from Yahoo! and another that displayed a five-day weather forecast.
Over the years, problems arose with the current weather image icon script that required various workarounds, such as switching to the French Yahoo! weather site for images.
A few months ago, all three weather scripts stopped working. I searched around for answers, which led me to various theories (see here and here) as to why the scripts no longer worked. Ultimately, the problem was due to a query change instituted by Yahoo! in its public API for retrieving weather conditions and forecasts.
I thought about patching the various scripts. Instead, I chose to base a consolidated solution for displaying a weather icon, current weather conditions, and forecast upon Thomas Upton’s original Python script, which I called weather-new.py, partnered with a custom Bash script called weather-condition.sh for assisting with the current weather icon handling.
The changes I made to the original Python script were four-fold:
- First, I modified the query request to Yahoo! Weather to use the new format request (more about that shortly);
- Second, I added output of a short weather description so that I could build a Bash “wrapper” script to select a corresponding weather image from a collection of icon files for display purposes;
- Third, I added day-night awareness to permit selection of day-night-dependent weather icons; and
- Fourth, I added the optional display of the sunrise and sunset times and a few other weather options such as wind chill (also known as the “feels-like” temperature).
Using the Yahoo! Weather Developer documentation, I added the additional data structures to the Python script needed to obtain the additional weather information, and I also added a few new runtime options for requesting the sunrise/sunset times, determining whether it is currently day or night, returning the weather code defined in the Yahoo! Weather Developer documentation, returning the last update time for the current weather conditions, and returning the wind chill.
I also used the query change information described here to alter how the script fetched weather information from Yahoo! One of the other consequences of the query change required a switch from using ZIP Codes to using WOEID (“Where On Earth ID”) as a location identifier. For example, queries that used to look simple like this:
changed into more complex queries that looked like this:
After making the query change to the Python script (and finding my WOEID, which I did here), collecting a set of weather icons that I liked, and creating a new Bash wrapper script for handling weather images, the results on my desktop look like this:
I’m rather pleased with the result.
If you’re a GeekTool user, here is how I constructed the above, with each rounded rectangle representing a different geeklet in GeekTool:
- ~/Applications/weather-condition.sh is a Bash script that calls Yahoo! weather via the weather-new.py Python script to obtain the short description of the current weather condition. Based on that description, the Bash shell copies the associated weather icon file to the location /tmp/weather.png.
- file:///tmp/weather.png shows the result of the ~/Applications/weather-condition.sh Bash script
- ~/Applications/weather-new.py –lvrs 12791684 calls Yahoo! weather and displays the location, sunrise, sunset, and current conditions in verbose mode for WOEID 12791684 (which is my location).
- ~/Applications/weather-new.py –-nocurr –f5 12791684 calls Yahoo! weather and displays a five-day forecast for my location without displaying the current weather status; echo Five day forecast: is for display purposes.
I’ve put the weather-new.py Python script, weather-condition.sh Bash script, and a set of weather icons into a zip archive, which you can grab here. I also put the geeklets in the archive for your use if you’re a GeekTool user. Just double-click the geeklets to install them into GeekTool, and customize the geeklets based on your WOEID and where you placed the scripts and weather icon folder. I placed mine in ~/Applications (the Applications folder inside my home folder, not the main Applications folder where applications are kept). If you place the scripts and weather icon folder into an alternative location, also make the corresponding location mods to the weather-condition.sh script.