German Weather Service regional weather report from the command line

As a cyclist who prefers to ride during nice weather, I like to check the weather every so often. In Germany, the German Weather Service (DWD) provides freely accessible and up-to-date weather reports. However, since I do not like having to navigate a bunch of sub-menus on a website, I thought this might be an interesting small weekend programming project. So, in my long-running journey of creating overly complicated Bash scripts that make my life easier, I added this new contraption. The code can be found below and an up-to-date version will be available in my dotfiles repo over on GitHub.

Basically, the script uses a combination of dmenu, imagemagick, GNU wget and imagemagick to create a montage of the weather reports for today and the following three days. At start, the user will be prompted to select the region for which the weather report shall be obtained. Also, one can set the default region through an environment variable DWD_LOCATION, e.g. by adding the following line to your ~/.profile.

export DWD_LOCATION=Bayern

For the chosen region, a weather report image for this morning, noon, late afternoon, and night are acquired as well as early and late weather for the following three days. Below you can se an example of what the final report looks like. The only issue is that DWD does delete images that describe the past. In this example generated in the early evening, the morning and noon images are replaced with placeholders.

Weather report made from a montage of DWD images
#!/usr/bin/env bash

# some variables, cache etc.

# first ask for location using dmenu, use $DWD_LOCATION if left empty
region=$(echo -e "$DWD_LOCATION (default set as env. variable DWD_LOCATION)\n\
Berlin und Brandenburg\n\
Niedersachsen und Bremen\n\
Rheinland-Pfalz und Saarland\n\
Schleswig-Holstein und Hamburg\n\
Deutschland" | dmenu -i -l 10 -p "Choose your region:")

# if used from $DWD_LOCATION, remove parantheses
region=$(echo $region | sed "s/\s*(.*)//g")

[[ "$region" = "Use $DWD_LOCATION" ]] && region=$DWD_LOCATION
[[ -z $region ]] && region="Deutschland"

# Substitute region for abbreviation. Used for creating URL.
case $region in
    "Bayern")                         abbr="bay" ;;
    "Baden-Württemberg")              abbr="baw" ;;
    "Berlin und Brandenburg")         abbr="bbb" ;;
    "Hessen")                         abbr="hes" ;;
    "Mecklenburg-Vorpommern")         abbr="mvp" ;;
    "Niedersachsen und Bremen")       abbr="nib" ;;
    "Nordrhein-Westfalen")            abbr="nrw" ;;
    "Rheinland-Pfalz und Saarland")   abbr="rps" ;;
    "Sachsen")                        abbr="sac" ;;
    "Sachsen-Anhalt")                 abbr="saa" ;;
    "Schleswig-Holstein und Hamburg") abbr="shh" ;;
    "Thüringen")                      abbr="thu" ;;
    "Deutschland")                    abbr="brd" ;;

# create and clean cache folder
mkdir -p $cache_folder
rm -f $cache_folder/*

# create urls and file order

# download the images
echo -e $order | xargs -P 10 -n 1 wget -qP $cache_folder > /dev/null

# imagemagick montage
montage $(echo -e $order | sed "s|https.*bilder|$cache_folder|g") -tile 2x5 -geometry +2+2 \

$img_program $cache_folder/dwd_wttr.jpg &

If you encounter any problems feel free to open an issue on GitHub.