Checking the weather from your Terminal

In Helsinki, it is no fun going out without a pocket umbrella – and regularly checking the weather year-round is a must. So, for fellow command-line enthusiasts, here is a useful utility for a quick rain check. AnsiWeather is a Shell script which connects to OpenWeatherMap.org’s API to fetch latest weather data, formats it using ANSI colors and Unicode symbols, then displays it your terminal. AnsiWeather uses ISO 3166-1 alpha-2 country codes. So, when checking for your local weather use compatible city/country formats as shown in the examples below. Please see this Wiki page for the full two-letters country list.

Installing AnsiWeather on Debian/Ubuntu

Update package lists;

$ apt update

Install the ANSI Weather utility

$ apt install ansiweather

** AnsiWeather requires additional packages to work. Please read the APT prompt and make sure you are fine with all the packages that will be installed before you proceed with the installation.

Checking your local weather

$ ansiweather Helsinki,FI

Or;

$ ansiweather stuttgart,de

Both commands will work as the script is not case-sensitive.

To check your local weather for the next five days, do;

$ ansiweather -l Helsinki,FI -u metric -s true -f 5 -d true

Or;

$ ansiweather -l stuttgart,de -u metric -s true -f 5 -d true

Again, capitalisation does not matter, and the maximum allowed number of days is 7.

Installing AnsiWeather on macOS

You can use Homebrew to install Linux binaries on macOS. Brew is Open Source and free and it works pretty much like APT.

First, install Brew using this one-liner;

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Update Brew;

$ brew update

This will fetch the latest version of Homebrew and all formulae lists from GitHub. It will also perform any necessary migrations.

Then, use Brew to install AnsiWeather;

$ brew install ansiweather

** If you run the above Brew command on macOS Catalina, Big Sur, or Montery and it fails, then you may want to run this command first, then trying again;

$ sudo chown -R $(whoami): /usr/local/share/zsh

This simply fixes the permissions on the zsh folder. More info can be found here.

Now, check your local weather by doing;

$ ansiweather -l Stuttgart,DE

Or;

$ ansiweather -l stuttgart,de -u metric -s true -f 5 -d true

Again, capitalisation does not matter.

The last command can be exhausting to type every time you want to check the week’s weather. See our brief article here on how to create command aliases for you daily used and complex Terminal interactions.

Attribution:

Thanks goes to Frederic Cambus for writing this cool script. Please check AnsiWeather’s GitHub repository for more details: https://github.com/fcambus/ansiweather.

Thanks also goes to Max Howell who wrote Homebrew. I consider it a life saver for users who want to safely run Linux binaries on macOS. You can check Homebrew’s blog for recent posts and announcements.

Starline contact

Any questions? Please contact us.

This proven expert for Linux and Ceph platforms joined Starline in 2018. His preference is for sophisticated open source solutions and tricky product developments. Therefore, he is also available for enquiries regarding PetaSAN and TrueNAS (formerly FreeNAS). But he also likes ARM servers from Ambedded or Mac operating systems. In his private life, the engineer enjoys working with 3D printers and robots.

Mohammad Ammar
Technical Support

Are you looking for an interesting and inspiring training position? Want to learn a thing or two about Linux and the leading Open-Source storage technologies? Starline is always looking for new members to join its team of Open-Source enthusiasts.