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
Clicking on https://wttr.in/ will load the website and show the weather based on your location (GeoIP)
Via the terminal
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
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
In the data centre, but want some fancy graphics in the terminal?
curl wttr\.in/Blackpool?format=3
Top Tip:
You can change the number afterformat=
to any number between 1 and 4 to change the format of the data. My favourite is 4.
Get the weather for multiple locations
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?
I added these lines to my .bashrc
file, a hidden file found in my home directory.
#Weather
curl -s 'wttr.in/Blackpool?format=3'
I also wrote a simple bash script that would create a pop up weather data to my desktop, fancy icons too!
#!/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
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!