Mercurial > hg > egg-tcls
comparison weather.tcl @ 418:e904b453a06a
weather: Show weather station coordinates and Google Maps link in the station list search.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Jan 2017 00:04:02 +0200 |
parents | ff932030a9b3 |
children | 3566fdca974b |
comparison
equal
deleted
inserted
replaced
417:3c42ad35e157 | 418:e904b453a06a |
---|---|
134 } | 134 } |
135 | 135 |
136 | 136 |
137 #------------------------------------------------------------------------- | 137 #------------------------------------------------------------------------- |
138 # Produce one location of weather data as a string | 138 # Produce one location of weather data as a string |
139 proc weather_get_data {udata ukey} { | 139 proc weather_get_str {udata umsg} { |
140 global weather_msg_result | 140 |
141 | |
142 # Set data to array | |
143 array unset uvals | 141 array unset uvals |
144 set uvals(station) [lindex $udata 0] | 142 set uvals(station) [lindex $udata 0] |
145 set uvals(type) [lindex $udata 1] | 143 set uvals(type) [lindex $udata 1] |
146 set uvals(c_lat) [lindex $udata 2] | 144 set uvals(c_lat) [lindex $udata 2] |
147 set uvals(c_long) [lindex $udata 3] | 145 set uvals(c_long) [lindex $udata 3] |
164 set uvals(humidity) [lindex $udata 7] | 162 set uvals(humidity) [lindex $udata 7] |
165 set uvals(wind_speed) [lindex $udata 8] | 163 set uvals(wind_speed) [lindex $udata 8] |
166 set uvals(cloud_cover) [lindex $udata 9] | 164 set uvals(cloud_cover) [lindex $udata 9] |
167 } | 165 } |
168 | 166 |
169 # Transform the format list | |
170 set astr "" | 167 set astr "" |
171 foreach aitem $weather_msg_result { | 168 foreach aitem $umsg { |
172 set atmp $aitem | 169 set atmp $aitem |
173 foreach {akey aval} [array get uvals] { | 170 foreach {akey aval} [array get uvals] { |
174 if {$aval != ""} { | 171 if {$aval != ""} { |
175 set atmp [string map [list "@${akey}@" $aval] $atmp] | 172 set atmp [string map [list "@${akey}@" $aval] $atmp] |
176 } | 173 } |
177 } | 174 } |
178 if {$atmp != $aitem} { | 175 if {$atmp != $aitem || [string first "@" $aitem] < 0} { |
179 append astr $atmp | 176 append astr $atmp |
180 } | 177 } |
181 } | 178 } |
182 | 179 |
183 return "$astr." | 180 return $astr |
184 } | 181 } |
185 | 182 |
186 | 183 |
187 # Get data by location key | 184 # Get data by location key |
188 proc weather_get_by_key {ukey} { | 185 proc weather_get_by_key {ukey} { |
189 global weather_data | 186 global weather_data weather_msg_result |
190 return [weather_get_data $weather_data($ukey) $ukey] | 187 return [weather_get_str $weather_data($ukey) $weather_msg_result] |
191 } | 188 } |
192 | 189 |
193 | 190 |
194 #------------------------------------------------------------------------- | 191 #------------------------------------------------------------------------- |
195 proc weather_update {} { | 192 proc weather_update {} { |
294 global weather_msg_usage_full weather_msg_usage_def_set weather_msg_user_not_known | 291 global weather_msg_usage_full weather_msg_usage_def_set weather_msg_user_not_known |
295 global weather_msg_no_results weather_msg_no_data_for_location | 292 global weather_msg_no_results weather_msg_no_data_for_location |
296 global weather_msg_usage_alias weather_msg_usage_unalias weather_msg_defloc | 293 global weather_msg_usage_alias weather_msg_usage_unalias weather_msg_defloc |
297 global weather_msg_aliased weather_msg_unaliased weather_msg_no_access | 294 global weather_msg_aliased weather_msg_unaliased weather_msg_no_access |
298 global weather_msg_def_set weather_msg_def_not_set weather_msg_aliases | 295 global weather_msg_def_set weather_msg_def_not_set weather_msg_aliases |
299 global weather_msg_usage_stations weather_msg_stations | 296 global weather_msg_usage_stations weather_msg_stations weather_msg_list_station |
297 global weather_msg_result | |
300 | 298 |
301 # Check and handle arguments | 299 # Check and handle arguments |
302 set rarglist [::textutil::split::splitx $uargs {\s+}] | 300 set rarglist [::textutil::split::splitx $uargs {\s+}] |
303 set rarg [lindex $rarglist 0] | 301 set rarg [lindex $rarglist 0] |
304 | 302 |
317 set rarg [join [lrange $rarglist 1 end] " "] | 315 set rarg [join [lrange $rarglist 1 end] " "] |
318 set result {} | 316 set result {} |
319 | 317 |
320 foreach {ukey uvalue} [array get weather_data] { | 318 foreach {ukey uvalue} [array get weather_data] { |
321 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { | 319 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { |
322 lappend result $ukey | 320 lappend result [weather_get_str $uvalue $weather_msg_list_station] |
323 } | 321 } |
324 } | 322 } |
325 | 323 |
326 set res [join $result " ; "] | 324 set res [join $result " ; "] |
327 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] | 325 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] |
439 set ufound 0 | 437 set ufound 0 |
440 set rarg [weather_get_alias $rarg] | 438 set rarg [weather_get_alias $rarg] |
441 foreach {ukey uvalue} [array get weather_data] { | 439 foreach {ukey uvalue} [array get weather_data] { |
442 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { | 440 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { |
443 if {[llength $uvalue] > 0} { | 441 if {[llength $uvalue] > 0} { |
444 weather_msg $upublic $unick $uchan [weather_get_data $uvalue $ukey] | 442 weather_msg $upublic $unick $uchan [weather_get_str $uvalue $weather_msg_result] |
445 incr nresults | 443 incr nresults |
446 } else { | 444 } else { |
447 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey] | 445 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey] |
448 } | 446 } |
449 incr ufound | 447 incr ufound |