Weather from wttr.in for Xmobar
Here I share my small script for making weather report in the Xmobar.
String format is:
<weather icon> <temperature in °C>(<feel like temperature in °C>)°C <wind direction>:<wind speed in meters per second>m/s <air humidity %>%
.
And each value is wrapped in its own color with <fc="color"> item </fc>
command for Xmobar.
Final output looks like this:
|
|
The source of weather data is wttr.in web-site, which is produced by this awesome project: chubin/wttr.in.
Motivation
I like Xmobar panel but it has issues with supporting of different colorful emoji icons. And while wttr.in
allows to produce quite useful pre-formatted weather reports (curl -s wttr.in/Bonn?format=4
) which I could feed directly in the status bar, but unfortunately Noto Color Emoji
icons used there are not displayed by Xmobar.
And I decided to write my own script as a workaround. Script is in Python because wttr.in
can give away information in JSON format. And processing of JSON in Python is quick and easy.
How it works
Prerequisites
- Running Xmobar (of course, this assumes you most probably use Xmonad window manager)
- Installed one of Nerd Fonts for use in the Xmobar.
- I use Hack Nerd Font.
cron
for regular weather updatespython3
has to be installed
Implementation logic
I want to have update of the weather status on the bar every minute while I want to keep number of requests to server as low as possible.
Here is what I do:
- I place my scripts in the
~/.scripts
directory. Hence, myweather-xmobar.py
script is placed there.- You can put it in any directory you put your own scripts.
- My
weather-xmobar.py
script runs every 30 min viacron
. And output is printed into the/tmp/weather
file. (You can define any interval you like). - Xmobar reads status from
/tmp/weather
file every 10 seconds. - In my
.xprofile
I produce initial/tmp/weather
file after boot and login. This is needed to avoid error on Xmobar because after login:- Internet connection is not yet available.
- Therefore
/tmp/weather
file does not exist and I have to create it.
I prefer use of
/tmp
because it istmpfs
built in RAM. Hence reading and writing there does is very fast and also do not use any SSD resource.
Config files
crontab -e
config:
|
|
Xmobar config (partial)
|
|
action
allows to update status on demand, e.g. if after boot it shows status as N/A. Just click on the status text on the Xmobar.
.xprofile
initiation line
Instead of simple cat "____N/A____" > /tmp/weather
I use my script because it also gives additional information about error.
|
|
The script itself
Script you can find on my Github project.