From: Siraaj Khandkar Date: Fri, 27 Jul 2018 15:44:25 +0000 (-0400) Subject: Take weather station ID as parameter (on update) X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=69f6cba9c389437ed45a103d9d15a67d947aeabd;p=khatus.git Take weather station ID as parameter (on update) --- diff --git a/bin/khatus_update_weather b/bin/khatus_update_weather index 1127141..665ae07 100755 --- a/bin/khatus_update_weather +++ b/bin/khatus_update_weather @@ -2,12 +2,18 @@ set -e -FILE_METAR_DECODED="$HOME/var/run/metar-KJFK-decoded" +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 KJFK 2>&1) > $FILE_METAR_DECODED # TODO: Better error handling +(metar -d "$STATION_ID" 2>&1) > $FILE_METAR_DECODED # TODO: Better error handling -awk ' +awk \ + -v file_fahrenheit="$FILE_TEMP_FAHRENHEIT" \ + -v file_celsius="$FILE_TEMP_CELSIUS" \ + ' /METAR pattern not found in NOAA data/ { failures++ } @@ -19,10 +25,11 @@ awk ' END { if (failures > 0) { - print "--"; + print "--" > file_fahrenheit + print "--" > file_celsius } else { - print fahrenheit; + print fahrenheit > file_fahrenheit + print celsius > file_celsius } }' \ - $FILE_METAR_DECODED \ -> $FILE_TEMP_FAHRENHEIT + $FILE_METAR_DECODED