Expose expiry character configuration
[khatus.git] / x1 / bin / khatus_update_weather
1 #! /bin/bash
2
3 set -e
4
5 STATION_ID="$1" # ICAO designator. e.g. KJFK, KBOS
6
7 FILE_METAR_DECODED="$HOME/var/run/metar-${STATION_ID}-decoded"
8 FILE_TEMP_FAHRENHEIT="${FILE_METAR_DECODED}-temp-fahrenheit"
9 FILE_TEMP_CELSIUS="${FILE_METAR_DECODED}-temp-celsius"
10
11 (metar -d "$STATION_ID" 2>&1) > $FILE_METAR_DECODED # TODO: Better error handling
12
13 awk \
14 -v file_fahrenheit="$FILE_TEMP_FAHRENHEIT" \
15 -v file_celsius="$FILE_TEMP_CELSIUS" \
16 '
17 /METAR pattern not found in NOAA data/ {
18 failures++
19 }
20
21 /^Temperature/ {
22 celsius = $3;
23 fahrenheit = (celsius * (9 / 5)) + 32;
24 }
25
26 END {
27 if (failures > 0) {
28 print "--" > file_fahrenheit
29 print "--" > file_celsius
30 } else {
31 print fahrenheit > file_fahrenheit
32 print celsius > file_celsius
33 }
34 }' \
35 $FILE_METAR_DECODED
This page took 0.07084 seconds and 4 git commands to generate.