summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmetar.sh11
1 files changed, 11 insertions, 0 deletions
diff --git a/metar.sh b/metar.sh
new file mode 100755
index 0000000..88b3ff4
--- /dev/null
+++ b/metar.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+read ICAO
+
+if ! echo "$ICAO" | grep -Eq "^([A-Z]|[a-z]){4}$" ; then
+ echo "error: invalid ICAO code!"
+ 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
+