summaryrefslogtreecommitdiff
path: root/metar.sh
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2023-02-13 12:12:47 +0000
committerLuke Bratch <luke@bratch.co.uk>2023-02-13 12:12:47 +0000
commitafc7689e9654c81cb65f3afe3088c3df7e3656d9 (patch)
tree0d4db24c3c6dc99a94cb7405989c22f90bc2c1f2 /metar.sh
Initial commit.
Diffstat (limited to 'metar.sh')
-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
+