Mercurial > hg > egg-tcls
comparison weather.tcl @ 287:748c6b44f572
weather: Fix translation routine.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 23 Jan 2015 17:21:42 +0200 |
parents | 899128d7c408 |
children | 088bb2621595 |
comparison
equal
deleted
inserted
replaced
286:899128d7c408 | 287:748c6b44f572 |
---|---|
135 return $uname | 135 return $uname |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 #------------------------------------------------------------------------- | 139 #------------------------------------------------------------------------- |
140 proc weather_translate_msg {amsg aargs} { | |
141 set aresult "" | |
142 foreach aitem $amsg { | |
143 set atmp $aitem | |
144 foreach {akey aval} [array get aargs] { | |
145 set atmp [string map [list "@${akey}@" $aval] $atmp] | |
146 } | |
147 if {$atmp != $aitem} { | |
148 append aresult $atmp | |
149 } | |
150 } | |
151 return $amsg | |
152 } | |
153 | |
154 | |
155 # Produce one location of weather data as a string | 140 # Produce one location of weather data as a string |
156 proc weather_get_data {udata ukey} { | 141 proc weather_get_data {udata ukey} { |
157 global weather_msg_result | 142 global weather_msg_result |
158 | 143 |
144 # Set data to array | |
159 array unset uvals | 145 array unset uvals |
160 array set uvals { | 146 set uvals(station) [lindex $udata 0] |
161 station [lindex udata 0] | 147 set uvals(type) [lindex $udata 1] |
162 vtime [lindex udata 2] | 148 set uvals(vtime) [lindex $udata 2] |
163 ctime [weather_ctime [lindex udata 2]] | 149 set uvals(ctime) [weather_ctime [lindex $udata 2]] |
164 temp [lindex udata 3] | 150 set uvals(temp) [lindex $udata 3] |
165 } | |
166 | 151 |
167 if {[lindex $udata 1] == 0} { | 152 if {[lindex $udata 1] == 0} { |
168 array set uvals { | 153 set uvals(weather1) [lindex $udata 5] |
169 weather1 [lindex udata 5] | 154 set uvals(weather2) [lindex $udata 6] |
170 weather2 [lindex udata 6] | 155 set uvals(road_temp) [lindex $udata 4] |
171 road_temp [lindex udata 4] | |
172 } | |
173 } else { | 156 } else { |
174 array set uvals { | 157 set uvals(humidity) [lindex $udata 4] |
175 humidity [lindex udata 4] | 158 set uvals(wind_speed) [lindex $udata 5] |
176 wind_speed [lindex udata 5] | 159 set uvals(cloud_cover) [lindex $udata 6] |
177 cloud_cover [lindex udata 6] | 160 } |
178 } | 161 |
179 } | 162 # Transform the format list |
180 | 163 set astr "" |
181 return "[weather_translate_msg $weather_msg_result $uvals]." | 164 foreach aitem $weather_msg_result { |
165 set atmp $aitem | |
166 foreach {akey aval} [array get uvals] { | |
167 if {$aval != ""} { | |
168 set atmp [string map [list "@${akey}@" $aval] $atmp] | |
169 } | |
170 } | |
171 if {$atmp != $aitem} { | |
172 append astr $atmp | |
173 } | |
174 } | |
175 | |
176 return "$astr." | |
182 } | 177 } |
183 | 178 |
184 | 179 |
185 # Get data by location key | 180 # Get data by location key |
186 proc weather_get_by_key {ukey} { | 181 proc weather_get_by_key {ukey} { |