Debian Codegraph @

misc/getstation

raw symbols SCIP
1 #!/bin/sh
2 #
3 BASE_URL="https://tgftp.nws.noaa.gov/data/observations/metar/stations"
4
5 usage () {
6 echo "Usage: $0 [-p] <station> [ <station> ... ]"
7 exit 1
8 }
9
10 date=`date -u '+%y%m%d'`
11 hour=`date -u '+%H'`
12
13 stations=""
14 pipe=""
15 while [ "$#" -gt 0 ]; do
16 case $1 in
17 -p)
18 pipe="YES"
19 shift;;
20 -*)
21 echo "unrecognized option: $1"
22 usage;;
23 [A-Z][A-Z0-9][A-Z0-9][A-Z0-9])
24 stations="$stations $1"
25 shift;;
26 esac
27 done
28
29 if [ -z "$stations" ]; then
30 usage
31 fi
32
33 for name in $stations; do
34 if [ -z "$pipe" ]; then
35 file="$name-${date}-${hour}Z.metar"
36 echo "Downloading current METAR report for station $name into $file"
37 curl -s -S -R "$BASE_URL/${name}.TXT" -o "$file"
38 else
39 curl -s -S -R "$BASE_URL/${name}.TXT" | grep "^$name "
40 fi
41 done
42