# HG changeset patch # User Matti Hamalainen # Date 1483826642 -7200 # Node ID e904b453a06aa8ad8f0f9a4ef0acaaa12715adbd # Parent 3c42ad35e15795e2f8ef7e17d5cf728e5427e955 weather: Show weather station coordinates and Google Maps link in the station list search. diff -r 3c42ad35e157 -r e904b453a06a config.weather.example --- a/config.weather.example Sat Jan 07 23:25:57 2017 +0200 +++ b/config.weather.example Sun Jan 08 00:04:02 2017 +0200 @@ -35,6 +35,9 @@ ### ### Messages ### +set weather_msg_list_station [list "\002@station@\002 ( http://www.google.fi/maps/@@c_lat@,@c_long@,15z )"] + + set weather_msg_result [list "\002@station@\002, mitattu klo @ctime@: \002@temp@°C\002"] lappend weather_msg_result ", @weather1@" lappend weather_msg_result ", keli @weather2@" diff -r 3c42ad35e157 -r e904b453a06a weather.tcl --- a/weather.tcl Sat Jan 07 23:25:57 2017 +0200 +++ b/weather.tcl Sun Jan 08 00:04:02 2017 +0200 @@ -136,10 +136,8 @@ #------------------------------------------------------------------------- # Produce one location of weather data as a string -proc weather_get_data {udata ukey} { - global weather_msg_result +proc weather_get_str {udata umsg} { - # Set data to array array unset uvals set uvals(station) [lindex $udata 0] set uvals(type) [lindex $udata 1] @@ -166,28 +164,27 @@ set uvals(cloud_cover) [lindex $udata 9] } - # Transform the format list set astr "" - foreach aitem $weather_msg_result { + foreach aitem $umsg { set atmp $aitem foreach {akey aval} [array get uvals] { if {$aval != ""} { set atmp [string map [list "@${akey}@" $aval] $atmp] } } - if {$atmp != $aitem} { + if {$atmp != $aitem || [string first "@" $aitem] < 0} { append astr $atmp } } - return "$astr." + return $astr } # Get data by location key proc weather_get_by_key {ukey} { - global weather_data - return [weather_get_data $weather_data($ukey) $ukey] + global weather_data weather_msg_result + return [weather_get_str $weather_data($ukey) $weather_msg_result] } @@ -296,7 +293,8 @@ global weather_msg_usage_alias weather_msg_usage_unalias weather_msg_defloc global weather_msg_aliased weather_msg_unaliased weather_msg_no_access global weather_msg_def_set weather_msg_def_not_set weather_msg_aliases - global weather_msg_usage_stations weather_msg_stations + global weather_msg_usage_stations weather_msg_stations weather_msg_list_station + global weather_msg_result # Check and handle arguments set rarglist [::textutil::split::splitx $uargs {\s+}] @@ -319,7 +317,7 @@ foreach {ukey uvalue} [array get weather_data] { if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { - lappend result $ukey + lappend result [weather_get_str $uvalue $weather_msg_list_station] } } @@ -441,7 +439,7 @@ foreach {ukey uvalue} [array get weather_data] { if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { if {[llength $uvalue] > 0} { - weather_msg $upublic $unick $uchan [weather_get_data $uvalue $ukey] + weather_msg $upublic $unick $uchan [weather_get_str $uvalue $weather_msg_result] incr nresults } else { weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey]