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 002200301a46704e1ca0dc73d2623c35b94a4710
parent e7aca6b3a039f0a7cb1aab165b4abbf11470f3c3
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 25 Jun 2020 22:49:39 +0200

Add weather fetcher script, replace wttr alias

Diffstat:
A.local/bin/weather | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M.profile | 2+-
2 files changed, 97 insertions(+), 1 deletion(-)

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 9520 +fi + +for zip in "$@"; do + show_weather "$zip" +done diff --git a/.profile b/.profile @@ -138,7 +138,7 @@ news() { fi w3m "$url" } -weather() { curl "wttr.in/?m"; } +#weather() { curl "wttr.in/?m"; } t_add() { transmission-remote --add --download-dir "$PWD" --encryption-required "$@"; } t_list() { transmission-remote --list; }