From efd0a19720e4da765ccf2c989e6741d9db88c437 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 8 Jul 2020 19:45:34 +0100 Subject: [PATCH] Add bin --- bin/bin/weather | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 bin/bin/weather diff --git a/bin/bin/weather b/bin/bin/weather new file mode 100755 index 0000000..8a6d851 --- /dev/null +++ b/bin/bin/weather @@ -0,0 +1,21 @@ +#!/bin/bash + +urlencode() { + # urlencode + old_lc_collate=$LC_COLLATE + LC_COLLATE=C + + local length="${#1}" + for (( i = 0; i < length; i++ )); do + local c="${1:i:1}" + case $c in + [a-zA-Z0-9.~_-]) printf "$c" ;; + *) printf '%%%02X' "'$c" ;; + esac + done + + LC_COLLATE=$old_lc_collate +} + +location=$(urlencode "${1:-St Helens}") +curl -s https://wttr.in/$location