Hund

Forecast - A simple Bash script for the weather service Yr.no

March 23, 2021

Some time ago, my rather old (zsh!) script for checking the current weather from the weather service Yr.no broke, after some looking around I found a new alternative called Forecast.

The script is written in Bash, and it’s pretty straightforward. It requires bash, curl and xsltproc.

This is the syntax for how you show the current weather:

$ forecast.sh -l "Sweden/Stockholm/Stockholm"
Stockholm, Sweden
Sunrise: 05:40  Sunset: 18:09
Forecast:
From 2021-03-23 10:00 to 12:00
Outlook: Clear sky 8°C
Wind: Light breeze 3.0 m/s W
Precipitation: 0 mm
Pressure: 1014.9 hPa

There are two flags available -l and -o. The -l flag is for location and the location itself is formated like Country/State/City. The -o flag is for offset, and the following time periods are available:

There are two flags available:

-l <Country/State/City> Let’s you set the location.
-o <N> Let’s you (optionally) set the time period.

The following time periods are available:

  • 23:30-05:30
  • 05:30-11:30
  • 11:30-17:30
  • 17:30-23:30.

Period-offset of 0 (default) gives the forecast for the current period. A value of 1 gives the forecast for the next period and so on.

Using it with Polybar

I mainly use it with Polybar to show the current weather like this:

A screenshort of my Polybar setup with Forecast.

Since the weather doesn’t change that often, I have chosen to use a cron job that runs once every hour and saves the data to a file that Polybar then reads.

The cron job looks like this:

forecast.sh -l "<Country>/<State>/<City>" -p 0 | grep "Outlook" | sed 's/Outlook: //'

And the command for Polybar looks like this:

[module/weather]
inherit = script/defaults
exec = cat /tmp/weather.log
format-prefix = " "
format-prefix-foreground = ${colors.blue}

Meta

No Comments

Use the e-mail form, if you wish to leave feedback for this post. Markdown is supported. [Terms of service]