summaryrefslogtreecommitdiff
path: root/metar.sh
blob: 88b3ff48750bd871a3fa834addde1124b563ef68 (plain)
1
2
3
4
5
6
7
8
9
10
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