14

Weather

Ansiweather is a small terminal program, that lets you check weather data via commands in the Terminal.

Open Terminal and run the command:

sudo apt-get install ansiweather 

Enter your password and hit enter. to install it.


Edit: If you get the error message sudo: apt-get: command not found, you might not have Xcode installed. But you can also install Ansiweather via the brew command.

If you don't already have brew installed, get it with:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After installing it, use the following command to install Ansiweather:

brew install ansiweather

Once you installed it you can run it in Terminal with the command:

ansiweather

To change the config file in Terminal run:

nano ~/.ansiweatherrc

There you can change the color of the output, location, greetings text etc. See https://github.com/fcambus/ansiweather for more details.

For example:

background:\33[0m
text:\33[0m
data:\33[32m
delimiter:\33[0m
dashes:\33[0m

location:London,GB

fetch_cmd:curl -s
units:metric
symbols:true
show_daylight:true
timeformat:%b %d %R
forecast:0
greeting_text:Weather in
wind_text:\nWind speed
humidity_text:\nHumidity
pressure_text:\nAir pressure
sunrise_text:\nSunrise
sunset_text:\nSunset

# Icons
sun:\xE2\x98\x80
moon:\xF0\x9F\x8C\x99
clouds:\xE2\x98\x81
rain:\xE2\x98\x94
fog:\xE2\x96\x92
mist:\xE2\x96\x91
haze:\xE2\x96\x91
snow:\xE2\x9D\x84
thunderstorm:\xE2\x9A\xA1

To change the colour of your output edit the 32 in data:\33[32m to a number of the ANSI colour code (FG Code). See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors for help. This however will only affect the data output. All other text colour can be edited in Geektool itself.

(You can also directly edit the icons with the help of the emoji & symbols keyboard ctrl+cmd+spacebar, e.g. sun:☀️ )

crtl+X to exit, Y+enter to accept changes.

Ansiweather cannot be run through the GeekTool Shell commands itself, therefore you have to work around a little bit. You can set up a Cronjob to create a .txt file of the Ansiweather output, which again can be displayed in Geektool. For that you have to edit the systemwide Crontab:

sudo nano /etc/crontab

Enter your password and hit enter. Insert following text:

SHELL=/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:

* * * * *       root ansiweather > /"Path where the Textfile should be saved".txt/

Change the asterisks to set up the refresh rate.

*\5 * * * * -> refreshing every 5 minutes.

30 * * * * -> resfreshing every half hour.

See https://crontab.guru/ for more options.

crtl+X to exit, Y+enter to accept changes.

Once you are happy with all your settings, create a new Shell window in Geektool and insert the command:

cat /"Path where the Textfile has been saved".txt/

As a font I used Helvetica Neue Thin.

Location Update

If you want to tell Ansiweather your current location you can write a small Shell-Script that will update the Ansiweather config file. Open Terminal and type:

nano /"Path where you want to save your shell-scrip".sh

And insert following text:

#!bash
curl "http://api.ipinfodb.com/v3/ip-city/?key=77aefa17ff64cff681bc8f6dd12f513b77356c469edbf1c345583451d45b07b2&format=raw" > /"Path of your location textfile".txt

city="$(cat /"Path of your location textfile".txt | cut -d ";" -f7)"

country="$(cat /"Path of your location textfile".txt | cut -d ";" -f4)"

perl -i -pe 's/.*/location:'${city}','${country}'/ if $.==7' ~/.ansiweatherrc

crtl+X to exit, Y+enter to accept changes.

This will get your location via the ipinfo.io-API, save the output as a textfile and copy the name of your city and country code into the Ansiweather config file. Be sure that location=Your City,XY is in the 7th row in your ~/.ansiweatherrc config file., otherwise edit $.==7 to the correct number of rows.

To set the refresh rate of the location-script you have to set up another Cronjob. This time it does not have to be systemwide. Use following command in Terminal:

export VISUAL=nano; crontab -e

and insert the text:

* * * * *    sh /"Path of your shell script".sh

Change the asterisks to set up the refresh rate.

*\5 * * * * -> refreshing every 5 minutes.

30 * * * * -> resfreshing every half hour.

See https://crontab.guru/ for more options.

crtl+X to exit, Y+enter to accept changes.

Please set up the refresh rate to more than 5 minutes, because it uses my personal API key, which only allows 60 queries per minute. Or create your own key for free at https://ipinfodb.com/register.php.


Comments

User Avatar
BigBadBobD 275 days ago
nice one
User Avatar
theelix1 254 days ago
nice post.
User Avatar
Geeklet 254 days ago
Thanks!
User Avatar
ejleon 247 days ago
Um...my terminal says "sudo: apt-get: command not found" HELP PLEASE??
User Avatar
Geeklet 236 days ago
If you don't have xcode installed the 'apt-get' command might not work for you, but you can also use 'brew'.

To install brew use the command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

(this will take a while and asks you to enter your user password)

After that you can use the following command to install Ansiweather:

brew install ansiweather

Log in to comment or register here.