commit 87d8dfebe8718fa58bb5c0a97d7728c9df76f8a0 parent bf88a350e09aeb0bbc20897f14bdd764e5693c80 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Sat, 17 Oct 2020 16:26:24 +0200 Revert "Remove non-working DMI weather reports" This reverts commit 9ace653cdb83432f0c235ee2e76596cf05fe7dc7. Diffstat:
D | .local/bin/clearoutside | | | 94 | ------------------------------------------------------------------------------- |
A | .local/bin/weather | | | 96 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 96 insertions(+), 94 deletions(-)
diff --git a/.local/bin/clearoutside b/.local/bin/clearoutside @@ -1,94 +0,0 @@ -#!/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 @@ -0,0 +1,96 @@ +#!/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