comparison weather.tcl @ 357:b1e7ffeaacef

weather: Adjust time output handling.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Dec 2015 23:13:04 +0200
parents 5c6cb115a7a1
children e06a3f3923f5
comparison
equal deleted inserted replaced
356:0de6e0c2c89c 357:b1e7ffeaacef
75 incr nline 75 incr nline
76 } 76 }
77 } 77 }
78 78
79 79
80 proc weather_ctime {utime} {
81 return [clock format $utime -format "%H:%M"]
82 }
83
84
85 proc weather_valid_user {uhand} { 80 proc weather_valid_user {uhand} {
86 if {$uhand != "" && $uhand != "{}" && $uhand != "*"} { 81 if {$uhand != "" && $uhand != "{}" && $uhand != "*"} {
87 return 1 82 return 1
88 } 83 }
89 return 0 84 return 0
147 # Set data to array 142 # Set data to array
148 array unset uvals 143 array unset uvals
149 set uvals(station) [lindex $udata 0] 144 set uvals(station) [lindex $udata 0]
150 set uvals(type) [lindex $udata 1] 145 set uvals(type) [lindex $udata 1]
151 set uvals(vtime) [lindex $udata 2] 146 set uvals(vtime) [lindex $udata 2]
152 set uvals(ctime) [weather_ctime [lindex $udata 2]] 147 set utime_d [expr [clock seconds] - $uvals(vtime)]
148 if {$utime_d < 3600} {
149 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M"]
150 } else {
151 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M (%D)"]
152 }
153
153 set uvals(temp) [lindex $udata 3] 154 set uvals(temp) [lindex $udata 3]
154 155
155 if {[lindex $udata 1] == 0} { 156 if {[lindex $udata 1] == 0} {
156 set uvals(weather1) [lindex $udata 5] 157 set uvals(weather1) [lindex $udata 5]
157 set uvals(weather2) [lindex $udata 6] 158 set uvals(weather2) [lindex $udata 6]
162 set uvals(cloud_cover) [lindex $udata 6] 163 set uvals(cloud_cover) [lindex $udata 6]
163 } 164 }
164 165
165 # Transform the format list 166 # Transform the format list
166 set astr "" 167 set astr ""
168 if {$utime_d >= 3600} {
169 set astr "** "
170 }
167 foreach aitem $weather_msg_result { 171 foreach aitem $weather_msg_result {
168 set atmp $aitem 172 set atmp $aitem
169 foreach {akey aval} [array get uvals] { 173 foreach {akey aval} [array get uvals] {
170 if {$aval != ""} { 174 if {$aval != ""} {
171 set atmp [string map [list "@${akey}@" $aval] $atmp] 175 set atmp [string map [list "@${akey}@" $aval] $atmp]