diff options
Diffstat (limited to '')
-rwxr-xr-x | metar | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -2,6 +2,17 @@ set -e + +metar_url () +{ + url="http://tgftp.nws.noaa.gov/data/observations/metar/decoded" + if test $# = 1; then + echo "${url}/${1}.TXT" + else + echo "${url}/" + fi +} + usage () { echo "usage: $0 (get | print | set STATION | list [PREFIX] | closest [LATITUDE LONGITUDE] [LIST])" @@ -49,14 +60,14 @@ list_stations () if test -z "$file"; then exit 1 fi - if ! curl -s "http://weather.noaa.gov/pub/data/observations/metar/decoded/" > "$file"; then + if ! curl -s "$(metar_url)" > "$file"; then unlink "$file" exit 1 fi list="$(sed -n 's/^.*<a href="\('"$1"'[A-Za-z0-9]*\)\.TXT">.*$/\1/p' "$file")" unlink "$file" for icao in $list; do - curl -s "http://weather.noaa.gov/pub/data/observations/metar/decoded/${icao}.TXT" | head -n 1 + curl -s "$(metar_url "${icao}")" | head -n 1 done } @@ -101,7 +112,7 @@ EOF } if test $# = 1 && test "$1" = "get"; then - curl -s "http://weather.noaa.gov/pub/data/observations/metar/decoded/$(get_station).TXT" || exit 1 + curl -s "$(metar_url "$(get_station)")" || exit 1 elif test $# = 1 && test "$1" = "print"; then get_station elif test $# = 2 && test "$1" = "set"; then |