Mercurial > hg > egg-tcls
diff weather.tcl @ 285:259f093c9503
weather: Make some more messages configurable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 23 Jan 2015 16:59:59 +0200 |
parents | 3893192d7aff |
children | 899128d7c408 |
line wrap: on
line diff
--- a/weather.tcl Fri Jan 23 13:20:28 2015 +0200 +++ b/weather.tcl Fri Jan 23 16:59:59 2015 +0200 @@ -48,6 +48,16 @@ } +proc weather_msg {apublic anick achan amsg {aargs {}}} { + set narg 1 + foreach marg $aargs { + set amsg [string map [list "%$narg" $marg] $amsg] + incr narg + } + weather_msg_do $apublic $anick $achan $amsg +} + + proc weather_usage {apublic anick achan amsg} { global weather_msg_usage_prefix_1 weather_msg_usage_prefix_2 set nline 0 @@ -64,13 +74,18 @@ } -proc weather_msg {apublic anick achan amsg {aargs {}}} { - set narg 1 - foreach marg $aargs { - set amsg [string map [list "%$narg" $marg] $amsg] - incr narg +proc weather_translate_msg {amsg aargs} { + set aresult "" + foreach aitem $amsg { + set atmp $aitem + foreach {akey aval} [array get aargs] { + set atmp [string map [list "@${akey}@" $aval] $atmp] + } + if {$atmp != $aitem} { + append aresult $atmp + } } - weather_msg_do $apublic $anick $achan $amsg + return $amsg } @@ -148,17 +163,31 @@ # Produce one location of weather data as a string proc weather_get_data {udata ukey} { - set str "\002[lindex $udata 0]\002, mitattu klo [weather_ctime [lindex $udata 2]]: \002[lindex $udata 3]°C\002" + global weather_msg_result + + array unset uvals + array set uvals { + station [lindex udata 0] + vtime [lindex udata 2] + ctime [weather_ctime [lindex udata 2]] + temp [lindex udata 3] + } + if {[lindex $udata 1] == 0} { - append str [weather_item $udata 5 ", @@"] - append str [weather_item $udata 6 ", keli @@"] - append str [weather_item $udata 4 ", tien pinta @@°C"] + array set uvals { + weather1 [lindex udata 5] + weather2 [lindex udata 6] + road_temp [lindex udata 4] + } } else { - append str [weather_item $udata 4 ", kosteus \002@@%\002"] - append str [weather_item $udata 5 ", tuuli \002@@\002 m/s"] - append str [weather_item $udata 6 ", pilvipeite \002@@\002"] + array set uvals { + humidity [lindex udata 4] + wind_speed [lindex udata 5] + cloud_cover [lindex udata 6] + } } - return "${str}." + + return "[weather_translate_msg $weather_msg_result $uvals]." }