Clear MPD state on non-0 exit from MPD song sensor
[khatus.git] / bin / khatus_parse_metar_d_output
CommitLineData
654ea6e2
SK
1#! /usr/bin/awk -f
2#
3# Qualifying the name as "_d_output" lest it be mistaken for parser of actual
4# metar format.
5
6function strip(s) {
3d53ab0d 7 sub("^ *", "", s)
654ea6e2
SK
8 sub(" *$", "", s)
9 return s
10}
11
12/METAR pattern not found in NOAA data/ {
13 failures++
14 exit
15}
16
17/[A-z][a-z]+ *: / {
18 split($0, line, ":")
19 key = strip(line[1])
20 val = strip(line[2])
21 values[NR] = val
22 first[key] = NR
23 last[key] = NR
24}
25
26/^ +/ {
27 values[NR] = strip($0)
28 last[key] = NR
29}
30
31END {
32 if (failures) {
33 print "metar fetch failed" > "/dev/stderr"
34 } else {
35 temp_string = values[first["Temperature"]]
36 split(temp_string, temp_parts, " +")
37 temp_celsius = temp_parts[1]
38 temp_fahrenheit = (temp_celsius * (9 / 5)) + 32
39 print "temperature " temp_fahrenheit "°F"
40 for (i=first["Phenomena"]; i<=last["Phenomena"]; i++) {
3fc7fe2c
SK
41 phenomenon = values[i]
42 if (phenomenon) {
43 print "phenomenon " phenomenon
44 }
654ea6e2
SK
45 }
46 }
47}
This page took 0.03444 seconds and 4 git commands to generate.