Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Fraasi
Last active January 5, 2023 23:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fraasi/3dab061f0590366e5de79858a4c780a3 to your computer and use it in GitHub Desktop.
Save Fraasi/3dab061f0590366e5de79858a4c780a3 to your computer and use it in GitHub Desktop.
simple wrapper function around http://wttr.io to get sensible defaults
#!/usr/bin/env bash
# simple wrapper function around http://wttr.io to get sensible defaults
# easily modified by changing the defaults and/or last parameters in the url
function wttr() {
USAGE="
Usage: wttr [OPTIONS]
Options:
-c <city> city name, double words with +, eg. new+york
-d <number> number of days to show, 0-3
-l <language> choose language, use wttr -w for options
-m show moon info instead of weather
-h print this help
-w curl wttr:help
-r region weather (experimental)
-g graph view (experimental)
"
# default values
CITY="Tampere"
LANG="fi"
DAYS=1
NARROW='n'
# If width > 125 cols, automatic wide mode
(( $(tput cols) > 125 )) && NARROW=''
OPTIND=1 # OPTIND is not automatically reset
while getopts "c:d:l:mhwrg" OPTNAME; do
case "$OPTNAME" in
c)
CITY=${OPTARG}
;;
d)
DAYS=${OPTARG}
;;
l)
LANG=${OPTARG}
;;
m)
curl -s "http://${LANG}.wttr.in/moon?F"
return 0
;;
h)
echo "$USAGE"
return 0
;;
w)
curl -s "http://wttr.in/:help"
return 0
;;
r)
curl -s "v3.wttr.in/${CITY}.sxl?F"
return 0
;;
g)
curl -s "v2.wttr.in/${CITY}?F"
return 0
;;
*)
echo "$USAGE"
return 1
;;
esac
done
curl -s "http://${LANG}.wttr.in/${CITY}?${DAYS}${NARROW}FMq"
}
wttr "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment