Mercurial > hg > egg-tcls
comparison weather.tcl @ 285:259f093c9503
weather: Make some more messages configurable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 23 Jan 2015 16:59:59 +0200 |
parents | 3893192d7aff |
children | 899128d7c408 |
comparison
equal
deleted
inserted
replaced
284:4ca3b5e39ca2 | 285:259f093c9503 |
---|---|
46 putserv "$weather_preferredmsg $anick :$amsg" | 46 putserv "$weather_preferredmsg $anick :$amsg" |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 | 50 |
51 proc weather_msg {apublic anick achan amsg {aargs {}}} { | |
52 set narg 1 | |
53 foreach marg $aargs { | |
54 set amsg [string map [list "%$narg" $marg] $amsg] | |
55 incr narg | |
56 } | |
57 weather_msg_do $apublic $anick $achan $amsg | |
58 } | |
59 | |
60 | |
51 proc weather_usage {apublic anick achan amsg} { | 61 proc weather_usage {apublic anick achan amsg} { |
52 global weather_msg_usage_prefix_1 weather_msg_usage_prefix_2 | 62 global weather_msg_usage_prefix_1 weather_msg_usage_prefix_2 |
53 set nline 0 | 63 set nline 0 |
54 foreach aline [split $amsg "\n"] { | 64 foreach aline [split $amsg "\n"] { |
55 if {[string range $aline 0 1] == ":"} { | 65 if {[string range $aline 0 1] == ":"} { |
62 incr nline | 72 incr nline |
63 } | 73 } |
64 } | 74 } |
65 | 75 |
66 | 76 |
67 proc weather_msg {apublic anick achan amsg {aargs {}}} { | 77 proc weather_translate_msg {amsg aargs} { |
68 set narg 1 | 78 set aresult "" |
69 foreach marg $aargs { | 79 foreach aitem $amsg { |
70 set amsg [string map [list "%$narg" $marg] $amsg] | 80 set atmp $aitem |
71 incr narg | 81 foreach {akey aval} [array get aargs] { |
72 } | 82 set atmp [string map [list "@${akey}@" $aval] $atmp] |
73 weather_msg_do $apublic $anick $achan $amsg | 83 } |
84 if {$atmp != $aitem} { | |
85 append aresult $atmp | |
86 } | |
87 } | |
88 return $amsg | |
74 } | 89 } |
75 | 90 |
76 | 91 |
77 proc weather_ctime {utime} { | 92 proc weather_ctime {utime} { |
78 return [clock format $utime -format "%H:%M"] | 93 return [clock format $utime -format "%H:%M"] |
146 } | 161 } |
147 | 162 |
148 | 163 |
149 # Produce one location of weather data as a string | 164 # Produce one location of weather data as a string |
150 proc weather_get_data {udata ukey} { | 165 proc weather_get_data {udata ukey} { |
151 set str "\002[lindex $udata 0]\002, mitattu klo [weather_ctime [lindex $udata 2]]: \002[lindex $udata 3]°C\002" | 166 global weather_msg_result |
167 | |
168 array unset uvals | |
169 array set uvals { | |
170 station [lindex udata 0] | |
171 vtime [lindex udata 2] | |
172 ctime [weather_ctime [lindex udata 2]] | |
173 temp [lindex udata 3] | |
174 } | |
175 | |
152 if {[lindex $udata 1] == 0} { | 176 if {[lindex $udata 1] == 0} { |
153 append str [weather_item $udata 5 ", @@"] | 177 array set uvals { |
154 append str [weather_item $udata 6 ", keli @@"] | 178 weather1 [lindex udata 5] |
155 append str [weather_item $udata 4 ", tien pinta @@°C"] | 179 weather2 [lindex udata 6] |
180 road_temp [lindex udata 4] | |
181 } | |
156 } else { | 182 } else { |
157 append str [weather_item $udata 4 ", kosteus \002@@%\002"] | 183 array set uvals { |
158 append str [weather_item $udata 5 ", tuuli \002@@\002 m/s"] | 184 humidity [lindex udata 4] |
159 append str [weather_item $udata 6 ", pilvipeite \002@@\002"] | 185 wind_speed [lindex udata 5] |
160 } | 186 cloud_cover [lindex udata 6] |
161 return "${str}." | 187 } |
188 } | |
189 | |
190 return "[weather_translate_msg $weather_msg_result $uvals]." | |
162 } | 191 } |
163 | 192 |
164 | 193 |
165 # Get data by location key | 194 # Get data by location key |
166 proc weather_get_by_key {ukey} { | 195 proc weather_get_by_key {ukey} { |