# HG changeset patch # User Matti Hamalainen # Date 1401734626 -10800 # Node ID 3a375ee7c106f4a24b82e49a4ba40441ba2897fb # Parent c8d5f3a7c4b70f48c12c2c8ed8cd8ab4daf22e82 weather: More flexible data handling. diff -r c8d5f3a7c4b7 -r 3a375ee7c106 weather.tcl --- a/weather.tcl Mon Jun 02 20:25:31 2014 +0300 +++ b/weather.tcl Mon Jun 02 21:43:46 2014 +0300 @@ -173,14 +173,19 @@ #------------------------------------------------------------------------- +proc weather_item {udata uindex ufmt} { + if {[llength $udata] > $uindex && [lindex $udata $uindex] != ""} { + set utmp [lindex $udata $uindex] + return [string map [list "@@" $utmp] $ufmt] + } + return "" +} + proc weather_get_data {ukey udata} { set str "\002[lindex $udata 0]\002, mitattu klo [weather_ctime [lindex $udata 1]]: \002[lindex $udata 2]°C\002" - if {[llength $udata] > 3} { - append str ", tien pinta [lindex $udata 3]°C" - } - if {[llength $udata] > 4} { - append str ", [lindex $udata 4]" - } + append str [weather_item $udata 4 ", @@"] + append str [weather_item $udata 5 ", kosteus \002@@%\002"] + append str [weather_item $udata 3 ", tien pinta @@°C"] return "${str}." }