comparison weather.tcl @ 279:f6dc673adfa1

weather: Reorder some function arguments.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 23 Jan 2015 12:23:43 +0200
parents 38a5bce4b078
children 3893192d7aff
comparison
equal deleted inserted replaced
278:9cab9cec110d 279:f6dc673adfa1
145 return "" 145 return ""
146 } 146 }
147 147
148 148
149 # Produce one location of weather data as a string 149 # Produce one location of weather data as a string
150 proc weather_get_data {ukey udata} {
151 set str "\002[lindex $udata 0]\002, mitattu klo [weather_ctime [lindex $udata 2]]: \002[lindex $udata 3]°C\002" 150 set str "\002[lindex $udata 0]\002, mitattu klo [weather_ctime [lindex $udata 2]]: \002[lindex $udata 3]°C\002"
151 proc weather_get_data {udata ukey} {
152 if {[lindex $udata 1] == 0} { 152 if {[lindex $udata 1] == 0} {
153 append str [weather_item $udata 5 ", @@"] 153 append str [weather_item $udata 5 ", @@"]
154 append str [weather_item $udata 6 ", keli @@"] 154 append str [weather_item $udata 6 ", keli @@"]
155 append str [weather_item $udata 4 ", tien pinta @@°C"] 155 append str [weather_item $udata 4 ", tien pinta @@°C"]
156 } else { 156 } else {
161 return "${str}." 161 return "${str}."
162 } 162 }
163 163
164 164
165 # Get data by location key 165 # Get data by location key
166 proc weather_get_key {ukey} { 166 proc weather_get_by_key {ukey} {
167 global weather_data 167 global weather_data
168 return [weather_get_data $ukey $weather_data($ukey)] 168 return [weather_get_data $weather_data($ukey) $ukey]
169 } 169 }
170 170
171 171
172 #------------------------------------------------------------------------- 172 #-------------------------------------------------------------------------
173 proc weather_update {} { 173 proc weather_update {} {
390 set nresults 0 390 set nresults 0
391 set rarglist [::textutil::split::splitx $rargs "\s*\;\s*"] 391 set rarglist [::textutil::split::splitx $rargs "\s*\;\s*"]
392 foreach rarg $rarglist { 392 foreach rarg $rarglist {
393 if {$rarg == "min"} { 393 if {$rarg == "min"} {
394 # Min temp 394 # Min temp
395 set umin [weather_get_key "w_min"] 395 set umin [weather_get_by_key "w_min"]
396 weather_msg $upublic $unick $uchan "Min: $umin" 396 weather_msg $upublic $unick $uchan "Min: $umin"
397 incr nresults 397 incr nresults
398 } elseif {$rarg == "max"} { 398 } elseif {$rarg == "max"} {
399 # Max temp 399 # Max temp
400 set umax [weather_get_key "w_max"] 400 set umax [weather_get_by_key "w_max"]
401 weather_msg $upublic $unick $uchan "Max: $umax" 401 weather_msg $upublic $unick $uchan "Max: $umax"
402 incr nresults 402 incr nresults
403 } elseif {$rarg == "minmax" || $rarg == "min max" || $rarg == "maxmin" || $rarg == "max min"} { 403 } elseif {$rarg == "minmax" || $rarg == "min max" || $rarg == "maxmin" || $rarg == "max min"} {
404 # Min & Max temps 404 # Min & Max temps
405 set umin [weather_get_key "w_min"] 405 set umin [weather_get_by_key "w_min"]
406 set umax [weather_get_key "w_max"] 406 set umax [weather_get_by_key "w_max"]
407 weather_msg $upublic $unick $uchan "Min: $umin | Max: $umax" 407 weather_msg $upublic $unick $uchan "Min: $umin | Max: $umax"
408 incr nresults 408 incr nresults
409 } else { 409 } else {
410 # Location match 410 # Location match
411 set ufound 0 411 set ufound 0
412 set rarg [weather_get_alias $rarg] 412 set rarg [weather_get_alias $rarg]
413 foreach {ukey uvalue} [array get weather_data] { 413 foreach {ukey uvalue} [array get weather_data] {
414 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { 414 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} {
415 if {[llength $uvalue] > 0} { 415 if {[llength $uvalue] > 0} {
416 weather_msg $upublic $unick $uchan [weather_get_data $ukey $uvalue] 416 weather_msg $upublic $unick $uchan [weather_get_data $uvalue $ukey]
417 incr nresults 417 incr nresults
418 } else { 418 } else {
419 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey] 419 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey]
420 } 420 }
421 incr ufound 421 incr ufound