X-Git-Url: https://git.xandkar.net/?p=khatus.git;a=blobdiff_plain;f=x1%2Fbin%2Fkhatus_update_weather;fp=x1%2Fbin%2Fkhatus_update_weather;h=665ae07198cd40636d22f42b2bf5d93b7ab27357;hp=0000000000000000000000000000000000000000;hb=499c58a269a00e031302938b5a8f006f23aae451;hpb=4c703fadbdc17d1753d16841582636598f862416 diff --git a/x1/bin/khatus_update_weather b/x1/bin/khatus_update_weather new file mode 100755 index 0000000..665ae07 --- /dev/null +++ b/x1/bin/khatus_update_weather @@ -0,0 +1,35 @@ +#! /bin/bash + +set -e + +STATION_ID="$1" # ICAO designator. e.g. KJFK, KBOS + +FILE_METAR_DECODED="$HOME/var/run/metar-${STATION_ID}-decoded" +FILE_TEMP_FAHRENHEIT="${FILE_METAR_DECODED}-temp-fahrenheit" +FILE_TEMP_CELSIUS="${FILE_METAR_DECODED}-temp-celsius" + +(metar -d "$STATION_ID" 2>&1) > $FILE_METAR_DECODED # TODO: Better error handling + +awk \ + -v file_fahrenheit="$FILE_TEMP_FAHRENHEIT" \ + -v file_celsius="$FILE_TEMP_CELSIUS" \ + ' + /METAR pattern not found in NOAA data/ { + failures++ + } + + /^Temperature/ { + celsius = $3; + fahrenheit = (celsius * (9 / 5)) + 32; + } + + END { + if (failures > 0) { + print "--" > file_fahrenheit + print "--" > file_celsius + } else { + print fahrenheit > file_fahrenheit + print celsius > file_celsius + } + }' \ + $FILE_METAR_DECODED