Checking weather from your Linux Terminal – Starline - Starline Computer: Storage und Server Lösungen von erfahrenen Experten

Checking the weather from your Terminal

How to use the AnsiWeather shell script to retrieve the latest weather data via 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.

1

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.

2

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.

3

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_logo_kontur_300
Enterprise Storage Solutions Team
Technik

Our experts are of course also experts in Linux, Ceph and ZFS