dotfiles

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

commit 9ace653cdb83432f0c235ee2e76596cf05fe7dc7
parent cb1342b72d84d63c673ac6cd79436064d7a8ce33
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed,  9 Sep 2020 07:40:56 +0200

Remove non-working DMI weather reports

Diffstat:
A.local/bin/clearoutside | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D.local/bin/weather | 96-------------------------------------------------------------------------------
2 files changed, 94 insertions(+), 96 deletions(-)

diff --git a/.local/bin/clearoutside b/.local/bin/clearoutside @@ -0,0 +1,94 @@ +#!/bin/sh +# requirements: hurl(1) or curl(1) + +image_viewer=xdg-open + +show_help() { + echo "usage: ${0##*/} [OPTIONS] ZIPCODE ..." + echo "shows Clear Outside weather forecast." + echo "Only works with danish zipcodes." + echo + echo "OPTIONS are one or more of the following:" + echo " -h show this message" + echo " -- do not consider any following args as options" +} + +die() { + printf '%s: error: %s\n' "${0##*/}" "$1" >&2 + exit 1 +} + +get_file() { + o="$(mktemp)" + $fetcher "$1" > "$o" + printf '%s\n' "$o" +} + +get_dmi_2day() { + get_file "https://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=${1}&mode=long&eps=true" +} + +get_dmi_9day() { + get_file "https://servlet.dmi.dk/byvejr/servlet/byvejr?by=${1}&tabel=dag3_9&eps=true" +} + +get_clear_outside() { + + if [ "$1" = 1000 ]; then + lon="55.68" + lat="12.57" + elif [ "$1" = 7700 ]; then + lon="56.96" + lat="8.70" + elif [ "$1" = 7730 ]; then + lon="57.10" + lat="8.72" + elif [ "$1" = 8000 ]; then + lon="56.16" + lat="10.20" + elif [ "$1" = 9520 ]; then + lon="56.84" + lat="9.89" + else + return + fi + + get_file "https://clearoutside.com/forecast_image_large/${lon}/${lat}/forecast.png" +} + +while :; do + case "$1" in + -h) + show_help + exit 0;; + --) # end all options + shift + break;; + -?*) + die "unknown option specified: $1";; + *) # No more options + break + esac + shift +done + +if command -v hurl >/dev/null 2>&1; then + fetcher=hurl +elif command -v curl >/dev/null 2>&1; then + fetcher=curl +else + die "hurl or curl not found" +fi + +show_weather() { + co="$(get_clear_outside "$1")" + $image_viewer "$co" +} + +if [ $# -lt 1 ]; then + show_weather 8000 +fi + +for zip in "$@"; do + show_weather "$zip" +done diff --git a/.local/bin/weather b/.local/bin/weather @@ -1,96 +0,0 @@ -#!/bin/sh -# requirements: hurl(1) or curl(1) - -image_viewer=xdg-open - -show_help() { - echo "usage: ${0##*/} [OPTIONS] ZIPCODE ..." - echo "shows DMI and Clear Outside weather forecast." - echo "Only works with danish zipcodes." - echo - echo "OPTIONS are one or more of the following:" - echo " -h show this message" - echo " -- do not consider any following args as options" -} - -die() { - printf '%s: error: %s\n' "${0##*/}" "$1" >&2 - exit 1 -} - -get_file() { - o="$(mktemp)" - $fetcher "$1" > "$o" - printf '%s\n' "$o" -} - -get_dmi_2day() { - get_file "https://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=${1}&mode=long&eps=true" -} - -get_dmi_9day() { - get_file "https://servlet.dmi.dk/byvejr/servlet/byvejr?by=${1}&tabel=dag3_9&eps=true" -} - -get_clear_outside() { - - if [ "$1" = 1000 ]; then - lon="55.68" - lat="12.57" - elif [ "$1" = 7700 ]; then - lon="56.96" - lat="8.70" - elif [ "$1" = 7730 ]; then - lon="57.10" - lat="8.72" - elif [ "$1" = 8000 ]; then - lon="56.16" - lat="10.20" - elif [ "$1" = 9520 ]; then - lon="56.84" - lat="9.89" - else - return - fi - - get_file "https://clearoutside.com/forecast_image_large/${lon}/${lat}/forecast.png" -} - -while :; do - case "$1" in - -h) - show_help - exit 0;; - --) # end all options - shift - break;; - -?*) - die "unknown option specified: $1";; - *) # No more options - break - esac - shift -done - -if command -v hurl >/dev/null 2>&1; then - fetcher=hurl -elif command -v curl >/dev/null 2>&1; then - fetcher=curl -else - die "hurl or curl not found" -fi - -show_weather() { - co="$(get_clear_outside "$1")" - dmi9="$(get_dmi_9day "$1")" - dmi2="$(get_dmi_2day "$1")" - $image_viewer "$co" "$dmi9" "$dmi2" -} - -if [ $# -lt 1 ]; then - show_weather 8000 -fi - -for zip in "$@"; do - show_weather "$zip" -done