12 for (i=2; i<=NF; i++) printf(" %s", $i);
15 /^[ \t]*Mute:/ {mute = $2}
16 /^[ \t]*front-left:/ {left = $4}
17 /^[ \t]*front-right:/ {right = $4}
22 printf("%s %s", left, right)
36 /^time: +[0-9]+:[0-9]+$/ {
38 seconds_current = time[1]
39 seconds_total = time[2]
41 hours = int(seconds_current / 60 / 60);
42 secs_beyond_hours = seconds_current - (hours * 60 * 60);
43 mins = int(secs_beyond_hours / 60);
44 secs = secs_beyond_hours - (mins * 60);
46 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
48 current_time = sprintf("%.2d:%.2d", mins, secs)
51 if (seconds_total > 0) {
52 time_percentage = (seconds_current / seconds_total) * 100
53 current_percentage = sprintf("%d%%", time_percentage)
55 current_percentage = "~"
60 state = status["state:"]
62 if (state == "play") {
64 } else if (state == "pause") {
66 } else if (state == "stop") {
74 status["state:"], current_time, current_percentage\
97 title = data["Title:"]
105 last = split(file, parts, "/")
116 weather_station_id
="$1"
117 metar
-d "$weather_station_id" 2>&1 \
119 /METAR pattern not found in NOAA data/ {
125 fahrenheit = (celsius * (9 / 5)) + 32;
126 temperature = fahrenheit
133 print temperature "°F"
138 date +'%a %b %d %H:%M:%S'
146 -v opt_mpd_song_max_chars
=10 \
151 db["volume"] = msg_body
158 db["mpd_curr_song_time"] = $2
159 db["mpd_curr_song_percent"] = $3
165 db["mpd_curr_song_name"] = msg_body
171 db["weather_temperature"] = msg_body
177 db["datetime"] = msg_body
187 function split_msg_parts() {
189 sub("^" msg_head " +", "")
191 debug(msg_head, msg_body)
194 function make_bar( position, bar, sep, i, j) {
195 position[++i] = sprintf("(%s)", db["volume"])
196 position[++i] = make_status_mpd()
197 position[++i] = db["weather_temperature"]
198 position[++i] = db["datetime"]
201 for (j = 1; j <= i; j++) {
202 bar = bar sep position[j]
208 function make_status_mpd( state, status) {
209 state = db["mpd_state"]
211 if (state == "play") {
212 status = make_status_mpd_state_known("▶")
213 } else if (state == "pause") {
214 status = make_status_mpd_state_known("❚❚")
215 } else if (state == "stop") {
216 status = make_status_mpd_state_known("⬛")
218 status = make_status_mpd_state_unknown("--")
221 return sprintf("[%s]", status)
224 function make_status_mpd_state_known(symbol) {
228 db["mpd_curr_song_time"],
229 db["mpd_curr_song_percent"],
230 substr(db["mpd_curr_song_name"], 1, opt_mpd_song_max_chars)\
234 function make_status_mpd_state_unknown(symbol) {
235 return sprintf("%s", symbol)
238 function debug(location, msg) {
240 print_error(location, msg)
244 function print_error(location, msg) {
245 print(location " ==> " msg) > "/dev/stderr"
260 echo "${msg_head} $($cmd)" > "$pipe"
267 dir_data
="$HOME/.khatus"
268 weather_station_id
='KJFK'
274 -l data-dir
:,weather-station
: \
286 weather_station_id
="$2"
296 ( echo "Khatus starting with the following parameters:"
297 ( echo " dir_data|= $dir_data"
298 echo " weather_station_id|= $weather_station_id"
303 pipe
="$dir_data/khatus_data_pipe"
309 # TODO: Redirect each worker's stderr to a dedicated log file
310 spawn produce_datetime
"$pipe" 'in:DATE_TIME' 1
311 spawn
"produce_weather $weather_station_id" "$pipe" 'in:WEATHER' $
(( 30 * 60 ))
312 spawn produce_mpd_state
"$pipe" 'in:MPD_STATE' 1
313 spawn produce_mpd_song
"$pipe" 'in:MPD_SONG' 1
314 spawn produce_volume
"$pipe" 'in:VOLUME' 1
315 spawn produce_bar_req
"$pipe" 'out:BAR' 1
This page took 0.118829 seconds and 4 git commands to generate.