diff options
-rwxr-xr-x | metar.sh | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -7,5 +7,16 @@ if ! echo "$ICAO" | grep -Eq "^([A-Z]|[a-z]){4}$" ; then exit 1 fi -xmllint --xpath 'string(/response/data/METAR/raw_text)' <(curl -s "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=$ICAO&hoursBeforeNow=1") | head -n1 +ICAO="$(echo "$ICAO" | tr "a-z" "A-Z")" +# aviationweather.gov +result1="$(xmllint --xpath 'string(/response/data/METAR/raw_text)' <(curl -s "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=$ICAO&hoursBeforeNow=1") | head -n1)" + +# metar-taf.com +result2="$(curl -s "https://metar-taf.com/history/$ICAO" | grep -E "METAR $ICAO [0-9]{6}Z" | head -n1 | sed "s/^\s*METAR // ; s|</td>|| ; s/\s*$//")" + +if [[ "$result1" > "$result2" ]] ; then + echo "$result1" +else + echo "$result2" +fi |