Mercurial > hg > egg-tcls
changeset 217:67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 28 Sep 2014 07:17:22 +0300 |
parents | 44593f1fb916 |
children | 861a49abee22 |
files | weather.tcl |
diffstat | 1 files changed, 28 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/weather.tcl Sun Sep 28 07:11:19 2014 +0300 +++ b/weather.tcl Sun Sep 28 07:17:22 2014 +0300 @@ -41,7 +41,9 @@ set weather_msg_usage_alias "alias <alias> = <nimi> (Lisää alias-nimen, esim. alias perse = turku)" set weather_msg_usage_unalias "unalias <alias> (Poistaa aliaksen)" -set weather_msg_usage_full "\[paikka\]\n$weather_msg_usage_def_set\n$weather_msg_usage_alias\n$weather_msg_usage_unalias" +set weather_msg_usage_stations "asemat <patterni> -- listaa mittausasemat joiden nimi matsaa patternin kanssa" + +set weather_msg_usage_full "\[paikka\]\n$weather_msg_usage_def_set\n$weather_msg_usage_alias\n$weather_msg_usage_unalias\n$weather_msg_usage_stations" set weather_msg_def_set "Vakio-havaintoasemiksi asetettu: \002%1\002." set weather_msg_defloc "Käyttäjän \002%1\002 vakio-havaintoasemat ovat: \002%2\002." @@ -54,6 +56,7 @@ set weather_msg_user_not_known "Tuntematon käyttäjä." set weather_msg_no_access "Ei oikeuksia muuttaa asetuksia." +set weather_msg_stations "Mittausasemat: %1" set weather_msg_no_results "\002%1\002: Ei mittaustietoja." set weather_msg_no_data_for_location "\002%1\002: Paikkakunnan tietoja ei saatu." @@ -313,6 +316,7 @@ 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 # Check and handle arguments set rarglist [::textutil::split::splitx $uargs {\s+}] @@ -322,9 +326,29 @@ weather_usage $upublic $unick $uchan "$weather_msg_usage_full" return 0 } - - # List or set the default weather station name patterns for this user - if {$rarg == "vakio" || $rarg == "default" || $rarg == "vakiot"} { + + if {$rarg == "asemat" || $rarg == "stations"} { + # List stations/locations matching the given pattern + if {[llength $rarglist] < 2} { + weather_usage $upublic $unick $uchan $weather_msg_usage_stations + return 0 + } + + set rarg [join [lrange $rarglist 1 end] " "] + set result {} + + foreach {ukey uvalue} [array get weather_data] { + if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { + lappend result $ukey + } + } + + set res [join $result " ; "] + weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] + return 0 + } elseif {$rarg == "vakio" || $rarg == "default" || $rarg == "vakiot"} { + # List or set the default weather station name patterns for this user + # Access check if {![weather_valid_user $uhand]} { weather_msg $upublic $unick $uchan $weather_msg_user_not_known