Take weather station ID as parameter (on update)
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 27 Jul 2018 15:44:25 +0000 (11:44 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Fri, 27 Jul 2018 15:44:25 +0000 (11:44 -0400)
bin/khatus_update_weather

index 1127141..665ae07 100755 (executable)
@@ -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
This page took 0.026896 seconds and 4 git commands to generate.