Mercurial > hg > egg-tcls
comparison weather.tcl @ 421:0f7524550aa2
weather: Cosmetics, stray whitespace.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Jan 2017 01:44:19 +0200 |
parents | 3566fdca974b |
children | 84d3d7abeb8a |
comparison
equal
deleted
inserted
replaced
420:db6e1d39db11 | 421:0f7524550aa2 |
---|---|
44 proc weather_msg_do {apublic anick achan amsg} { | 44 proc weather_msg_do {apublic anick achan amsg} { |
45 global weather_preferredmsg | 45 global weather_preferredmsg |
46 if {$apublic == 1} { | 46 if {$apublic == 1} { |
47 putserv "$weather_preferredmsg $achan :$amsg" | 47 putserv "$weather_preferredmsg $achan :$amsg" |
48 } else { | 48 } else { |
49 putserv "$weather_preferredmsg $anick :$amsg" | 49 putserv "$weather_preferredmsg $anick :$amsg" |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 proc weather_msg {apublic anick achan amsg {aargs {}}} { | 54 proc weather_msg {apublic anick achan amsg {aargs {}}} { |
90 global weather_aliasfile weather_aliases | 90 global weather_aliasfile weather_aliases |
91 | 91 |
92 # Create dict | 92 # Create dict |
93 array unset weather_aliases | 93 array unset weather_aliases |
94 array set weather_aliases {} | 94 array set weather_aliases {} |
95 | 95 |
96 # Read datafile | 96 # Read datafile |
97 if {![catch {set ufile [open $weather_aliasfile r 0600]} uerrmsg]} { | 97 if {![catch {set ufile [open $weather_aliasfile r 0600]} uerrmsg]} { |
98 while {![eof $ufile]} { | 98 while {![eof $ufile]} { |
99 gets $ufile uline | 99 gets $ufile uline |
100 set udata [split $uline "|"] | 100 set udata [split $uline "|"] |
211 set utemp [lindex $udata 6] | 211 set utemp [lindex $udata 6] |
212 set ukey [lindex $udata 0] | 212 set ukey [lindex $udata 0] |
213 | 213 |
214 set weather_data($ukey) $udata | 214 set weather_data($ukey) $udata |
215 | 215 |
216 if {[string is double -strict $utemp]} { | 216 if {[string is double -strict $utemp]} { |
217 if {$utemp < $wtemp_min_val} { | 217 if {$utemp < $wtemp_min_val} { |
218 set wtemp_min_key $ukey | 218 set wtemp_min_key $ukey |
219 set wtemp_min_val $utemp | 219 set wtemp_min_val $utemp |
220 } | 220 } |
221 if {$utemp > $wtemp_max_val} { | 221 if {$utemp > $wtemp_max_val} { |
224 } | 224 } |
225 } | 225 } |
226 } | 226 } |
227 } | 227 } |
228 close $ufile | 228 close $ufile |
229 | 229 |
230 # Store min/max | 230 # Store min/max |
231 if {$wtemp_min_key != "" && $wtemp_max_key != ""} { | 231 if {$wtemp_min_key != "" && $wtemp_max_key != ""} { |
232 set weather_data(w_min) $weather_data($wtemp_min_key) | 232 set weather_data(w_min) $weather_data($wtemp_min_key) |
233 set weather_data(w_max) $weather_data($wtemp_max_key) | 233 set weather_data(w_max) $weather_data($wtemp_max_key) |
234 } else { | 234 } else { |
242 | 242 |
243 | 243 |
244 #------------------------------------------------------------------------- | 244 #------------------------------------------------------------------------- |
245 # Weather data update loop | 245 # Weather data update loop |
246 proc weather_exec {} { | 246 proc weather_exec {} { |
247 global weather_check_period weather_running | 247 global weather_check_period weather_running |
248 | 248 |
249 # Perform update | 249 # Perform update |
250 weather_update | 250 weather_update |
251 | 251 |
252 # Schedule next update | 252 # Schedule next update |
315 set rarg [join [lrange $rarglist 1 end] " "] | 315 set rarg [join [lrange $rarglist 1 end] " "] |
316 set result {} | 316 set result {} |
317 | 317 |
318 foreach {ukey uvalue} [array get weather_data] { | 318 foreach {ukey uvalue} [array get weather_data] { |
319 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { | 319 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { |
320 lappend result [weather_get_str $uvalue $weather_msg_list_station] | 320 lappend result [weather_get_str $uvalue $weather_msg_list_station] |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 set res [join $result " ; "] | 324 set res [join $result " ; "] |
325 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] | 325 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] |
330 # Access check | 330 # Access check |
331 if {![weather_valid_user $uhand]} { | 331 if {![weather_valid_user $uhand]} { |
332 weather_msg $upublic $unick $uchan $weather_msg_user_not_known | 332 weather_msg $upublic $unick $uchan $weather_msg_user_not_known |
333 return 0 | 333 return 0 |
334 } | 334 } |
335 | 335 |
336 if {[llength $rarglist] == 1} { | 336 if {[llength $rarglist] == 1} { |
337 set lista [getuser $uhand XTRA "weather_locations"] | 337 set lista [getuser $uhand XTRA "weather_locations"] |
338 if {$lista == "" || $lista == "{}"} { | 338 if {$lista == "" || $lista == "{}"} { |
339 weather_msg $upublic $unick $uchan $weather_msg_def_not_set [list $uhand] | 339 weather_msg $upublic $unick $uchan $weather_msg_def_not_set [list $uhand] |
340 } else { | 340 } else { |
365 set nlist [lsearch -all -inline -not -exact $qlist ""] | 365 set nlist [lsearch -all -inline -not -exact $qlist ""] |
366 if {[llength $nlist] < 2} { | 366 if {[llength $nlist] < 2} { |
367 weather_usage $upublic $unick $uchan $weather_msg_usage_alias | 367 weather_usage $upublic $unick $uchan $weather_msg_usage_alias |
368 return 0 | 368 return 0 |
369 } | 369 } |
370 | 370 |
371 set ualias [lindex $nlist 0] | 371 set ualias [lindex $nlist 0] |
372 set uname [lindex $nlist 1] | 372 set uname [lindex $nlist 1] |
373 set weather_aliases($ualias) $uname | 373 set weather_aliases($ualias) $uname |
374 weather_msg $upublic $unick $uchan $weather_msg_aliased [list $ualias $uname] | 374 weather_msg $upublic $unick $uchan $weather_msg_aliased [list $ualias $uname] |
375 | 375 |
444 } else { | 444 } else { |
445 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey] | 445 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey] |
446 } | 446 } |
447 incr ufound | 447 incr ufound |
448 } | 448 } |
449 | 449 |
450 # Check for results limit | 450 # Check for results limit |
451 if {$nresults >= $weather_max_results} { | 451 if {$nresults >= $weather_max_results} { |
452 return 0 | 452 return 0 |
453 } | 453 } |
454 } | 454 } |
455 | 455 |
456 if {$ufound == 0} { | 456 if {$ufound == 0} { |
457 weather_msg $upublic $unick $uchan $weather_msg_no_data_for_location [list $rarg] | 457 weather_msg $upublic $unick $uchan $weather_msg_no_data_for_location [list $rarg] |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 # Check for results limit | 461 # Check for results limit |
462 if {$nresults >= $weather_max_results} { | 462 if {$nresults >= $weather_max_results} { |
463 return 0 | 463 return 0 |
464 } | 464 } |
465 } | 465 } |