I’ve known about wttr.in for quite some time, a gem of the internet. While I’d occasionally access it from the command line and marvel at it, I just couldn’t figure out a way to make it a part of my workspace or workflow. There’s definitely times when I get curious about the temperature or would like to know the sunset time or phase of the moon. Quickly searching through my command history to find the relevant url to pass to
curl was as far as I’d gotten until now. No more.
I knew I didn’t want weather information permanently on my status bar. That’s how I’ve felt about weather information on my phone as well. But I do want it quickly accessible for when I want to know. The solution? A tiny script that I can call upon from my launcher, which generates a pretty weather report notification.
The site has an entire section on one-line outputs, meant to play nice with status bars and the script just chains together a whole bunch of these to create the notification. The first question to answer was what all did I want to display. With a total of 20 variables available, it was too easy to go overboard. I finally settled upon the following:
- the current temperature and what it feels like
- sunrise and sunset timings for golden hour needs
- present weather condition because the output sure looks nice
- phase of the moon because I’m always afraid of missing the full moon
The script stores each of these in a variable, outputs it into a single file, formats it for
notify-send and then I just call upon it to get this nice-looking1 notification:
The script in its full and tiny glory here:
#!/bin/sh condition="$(curl wttr.in/?format=%C+%c)" temp="$(curl wttr.in/?format='%t+(%f)')" sunrise="Sunrise: $(curl wttr.in/?format=%S)" sunset="Sunset: $(curl wttr.in/?format=%s)" moon="Moon Phase: $(curl wttr.in/?format=%m)" echo -e "$condition\n$temp\n$sunrise\n$sunset\n$moon" > /tmp/weather sed -i 's/$/\\n/' /tmp/weather paste -sd '' /tmp/weather > /tmp/weather2 sed -i 's/^/"/' /tmp/weather2 && sed -i 's/$/"/' /tmp/weather2 cat /tmp/weather2 | xargs -n 1 notify-send 'Weather Report' -i 'weather.png' rm /tmp/weather /tmp/weather2
Could this be better? I’m sure anyone more experienced could optimise it and if that’s you, I would love to hear from you. Is this cool? I think so but definitely not enough to beat that temperature.