/ tuesdaytooling

Tooling Tuesday: wttr

Recently across Europe it has been a bit warm, but Sys Admin's typically live in AC cooled data centres, so how can they learn what the weather is like?

So what is it?

wttr is a website and tool that is awesome! It provides clear information on the weather, in a webpage or in the terminal.
The tool was written by Igor Chubin and on his Github page there are examples on how to use the tool.

So how do I use it?

There is nothing to install! Woohoo!

Via the website

Screenshot-from-2019-07-26-22-13-33
Clicking on https://wttr.in/ will load the website and show the weather based on your location (GeoIP)

Via the terminal

Screenshot-from-2019-07-26-22-14-51
In the data centre? Not got access to a web browser? Then use curl to get the weather data from the site and display it in the terminal!
Here I get the weather for Blackpool, but replace this with where you live, or want to know the weather for.

curl wttr\.in/Blackpool

Fancy stuff!

Generate a PNG image

blackpool
It isn't just ASCII based text in a terminal or browser. Need the weather as a PNG image? I got ya!

curl wttr\.in/Blackpool.png -o blackpool.png

Nice weather icons in the terminal

Screenshot-from-2019-07-26-22-28-04
In the data centre, but want some fancy graphics in the terminal?

curl wttr\.in/Blackpool?format=3

Screenshot-from-2019-07-26-22-33-15
Top Tip:
You can change the number after format= to any number between 1 and 4 to change the format of the data. My favourite is 4.

Get the weather for multiple locations

Screenshot-from-2019-07-26-23-13-44
Going somewhere? Family living away? Then with this line of code you can see the weather in multiple locations!

curl -s 'wttr.in/{Blackpool,Cleveland,Lyon}?format=4'

So what did I do with it?

Screenshot-from-2019-07-29-20-58-12
I added these lines to my .bashrc file, a hidden file found in my home directory.

#Weather
curl -s 'wttr.in/Blackpool?format=3'

Screenshot-from-2019-07-29-21-00-03

Screenshot-from-2019-07-29-21-40-08
I also wrote a simple bash script that would create a pop up weather data to my desktop, fancy icons too!
Screenshot-from-2019-07-29-21-35-43

#!/bin/bash
WEATHER="$(curl -s 'wttr.in/Blackpool?format=3')"
notify-send "${WEATHER}"

So where can I learn more?

Head over to the wttr help page and learn more about this great tool.

Bonus Content

Screenshot-from-2019-07-30-08-50-29
Do you need the weather from wttr in your Python code? I got ya!

import requests
blackpool = requests.get('https://wttr.in/Blackpool?format=3')
print('The weather today for...'+blackpool.text)

Here I use requests to get the data from wttr and then print the data to the Python shell (REPL). Notice that the lovely icons are still there! Result!