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