dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles # fast
git clone https://src.adamsgaard.dk/dotfiles.git # slow
Log | Files | Refs | README | LICENSE Back to index

forecast (1069B)


      1 #!/bin/sh
      2 set -e
      3 
      4 default_zipcode=9520 # Skoerping
      5 
      6 show_help() {
      7 	echo "usage: ${0##*/} [radar | 3-9 | wind] [ZIPCODE]"
      8 	echo "gets DMI forecast, with ZIPCODE=$default_zipcode by default"
      9 }
     10 
     11 if command -v open >/dev/null 2>&1; then
     12 	open=open
     13 elif command -v xdg-open >/dev/null 2>&1; then
     14 	open=xdg-open
     15 else
     16 	open="echo"
     17 fi
     18 
     19 get_url() {
     20 	echo "http://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=${1}&mode=long&eps=true"
     21 }
     22 
     23 if [ $# -gt 0 ]; then
     24 	if [ "$1" = "radar" ]; then
     25 		$open "http://www.dmi.dk/vejr/maalinger/radar-nedboer/"
     26 		exit 0
     27 	elif [ "$1" = "3-9" ]; then
     28 		if [ $# -gt 1 ]; then
     29 			zip="$2"
     30 		else
     31 			zip="$default_zipcode"
     32 		fi
     33 		url="http://servlet.dmi.dk/byvejr/servlet/byvejr?by=${zip}&tabel=dag3_9&eps=true"
     34 	elif [ "$1" = "wind" ]; then
     35 		url="http://servlet.dmi.dk/bv/servlet/bvImage?stat=6065&param=wind"
     36 	elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
     37 		show_help
     38 		exit 0
     39 	else
     40 		url=$(get_url "$1")
     41 	fi
     42 else
     43 	url=$(get_url $default_zipcode)
     44 fi
     45 
     46 tmpfile=$(mktemp).png
     47 curl --silent --location "$url" --output "$tmpfile"
     48 $open "$tmpfile"