summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2023-02-28 19:40:27 +0000
committerLuke Bratch <luke@bratch.co.uk>2023-02-28 19:40:27 +0000
commitcab85771bb4054e1c020c4cd9ccac1363268a28d (patch)
treee7da8c755eeb25a4981b44a9babe63e9a8d64bfb
parentafc7689e9654c81cb65f3afe3088c3df7e3656d9 (diff)
Add a second METAR source and output whichever is newer.
-rwxr-xr-xmetar.sh13
1 files changed, 12 insertions, 1 deletions
diff --git a/metar.sh b/metar.sh
index 88b3ff4..599d57f 100755
--- a/metar.sh
+++ b/metar.sh
@@ -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