annotate weather.tcl @ 536:1044fbacb8a7

weather: Use utl_valid_user instead of weather_valid_user.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 07 Jul 2020 14:42:40 +0300
parents edbc0190e82a
children 210d22dac6d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #
499
3da1d036ae48 weather: Bump version, adjust copyright message when loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
3 # Weather v1.2.0 by Matti 'ccr' Hamalainen <ccr@tnsp.org>
487
b4be881a9908 fetch_weather, weather: Add primitive support for wind direction data.
Matti Hamalainen <ccr@tnsp.org>
parents: 455
diff changeset
4 # (C) Copyright 2014-2020 Tecnic Software productions (TNSP)
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #
183
4abb7a940e24 weather: Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
6 # Requires data fetcher to be run as a cronjob, see fetch_weather.pl
4abb7a940e24 weather: Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
7 # for more information.
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 # This script is freely distributable under GNU GPL (version 2) license.
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
273
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
13 ### The configuration should be in config.weather in same directory
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
14 ### as this script. Or change the line below to point where ever
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
15 ### you wish. See "config.weather.example" for an example config file.
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
16 source [file dirname [info script]]/config.weather
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
344
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
18 ### Required utillib.tcl
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
19 source [file dirname [info script]]/utillib.tcl
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
20
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 # No need to look below this line
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 set weather_name "Weather"
499
3da1d036ae48 weather: Bump version, adjust copyright message when loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
26 set weather_version "1.2.0"
184
a496dc87a7c1 weather: Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 183
diff changeset
27
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 ### Initialization messages
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 package require textutil::split
499
3da1d036ae48 weather: Bump version, adjust copyright message when loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
31 set weather_message "$weather_name v$weather_version (C) 2014-2020 ccr/TNSP"
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 putlog "$weather_message"
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 proc weather_log {arg} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 global weather_logmsg weather_name
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 if {$weather_logmsg != 0} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 putlog "$weather_name: $arg"
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
426
84d3d7abeb8a Add utl_msg_do() function into utillib and refactor out similar things in quotedb and weather scripts.
Matti Hamalainen <ccr@tnsp.org>
parents: 421
diff changeset
44 proc weather_msg {apublic anick achan amsg {aargs {}}} {
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 global weather_preferredmsg
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
46 set narg 1
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
47 foreach marg $aargs {
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
48 set amsg [string map [list "%$narg" $marg] $amsg]
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
49 incr narg
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
50 }
426
84d3d7abeb8a Add utl_msg_do() function into utillib and refactor out similar things in quotedb and weather scripts.
Matti Hamalainen <ccr@tnsp.org>
parents: 421
diff changeset
51 utl_msg_do $weather_preferredmsg $apublic $anick $achan $amsg
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
52 }
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
53
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
54
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
55 proc weather_usage {apublic anick achan amsg} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
56 global weather_msg_usage_prefix_1 weather_msg_usage_prefix_2
429
1ada0cb9bdd9 weather: Some stray weather_msg_do calls were left in, fix those.
Matti Hamalainen <ccr@tnsp.org>
parents: 426
diff changeset
57 global weather_preferredmsg
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
58 set nline 0
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
59 foreach aline [split $amsg "\n"] {
203
28ee3578a6d1 Weather: Add support for usage messages without default prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
60 if {[string range $aline 0 1] == ":"} {
429
1ada0cb9bdd9 weather: Some stray weather_msg_do calls were left in, fix those.
Matti Hamalainen <ccr@tnsp.org>
parents: 426
diff changeset
61 utl_msg_do $weather_preferredmsg $apublic $anick $achan $aline
203
28ee3578a6d1 Weather: Add support for usage messages without default prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
62 } elseif {$nline == 0} {
429
1ada0cb9bdd9 weather: Some stray weather_msg_do calls were left in, fix those.
Matti Hamalainen <ccr@tnsp.org>
parents: 426
diff changeset
63 utl_msg_do $weather_preferredmsg $apublic $anick $achan "$weather_msg_usage_prefix_1$aline"
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
64 } else {
429
1ada0cb9bdd9 weather: Some stray weather_msg_do calls were left in, fix those.
Matti Hamalainen <ccr@tnsp.org>
parents: 426
diff changeset
65 utl_msg_do $weather_preferredmsg $apublic $anick $achan "$weather_msg_usage_prefix_2$aline"
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
66 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
67 incr nline
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
68 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
69 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
70
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
71
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
72 #-------------------------------------------------------------------------
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
73 proc weather_load_aliases {} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
74 global weather_aliasfile weather_aliases
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
75
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
76 # Create dict
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
77 array unset weather_aliases
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
78 array set weather_aliases {}
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
79
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
80 # Read datafile
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
81 if {![catch {set ufile [open $weather_aliasfile r 0600]} uerrmsg]} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
82 while {![eof $ufile]} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
83 gets $ufile uline
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
84 set udata [split $uline "|"]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
85 if {[llength $udata] == 2} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
86 set weather_aliases([lindex $udata 0]) [lindex $udata 1]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
87 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
88 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
89 close $ufile
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
90 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
91 weather_log "Could not open data file: $uerrmsg"
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
92 }
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
93 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
94
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
95
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
96 proc weather_save_aliases {} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
97 global weather_aliasfile weather_aliases
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
98
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
99 if {![catch {set ufile [open $weather_aliasfile w 0600]} uerrmsg]} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
100 foreach {ukey uvalue} [array get weather_aliases] {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
101 puts $ufile "$ukey|$uvalue"
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
102 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
103 close $ufile
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
104 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
105 weather_log "Could not open data file: $uerrmsg"
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
106 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
107 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
108
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
109
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
110 # If there exists an alias for given string/name, return it
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
111 proc weather_get_alias {uname} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
112 global weather_aliases
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
113 set utmp [array get weather_aliases $uname]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
114 if {[llength $utmp] > 0} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
115 return [lindex $utmp 1]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
116 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
117 return $uname
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
118 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
119
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
120
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 proc weather_update {} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 global weather_datafile weather_data
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
172
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
125 # Check if we can open the weather data file
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
126 if {![catch {set ufile [open $weather_datafile r 0600]} uerrmsg]} {
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
127 # Create dict
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
128 array unset weather_data
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
129 array set weather_data {}
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
130
172
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
131 set wtemp_min_val 500000
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
132 set wtemp_max_val -500000
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
133 set wtemp_min_key ""
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
134 set wtemp_max_key ""
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
135
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
136 # Read in the data
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 while {![eof $ufile]} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 gets $ufile uline
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 set udata [split $uline "|"]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 if {[llength $udata] > 0} {
414
d623652df6b5 fetch_weather / weather: Add weather measurement station location data (GPS WGS-84 lat/long/height) to weather cache. Not used in weather.tcl yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
141 set utemp [lindex $udata 6]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 set ukey [lindex $udata 0]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 set weather_data($ukey) $udata
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
146 if {[string is double -strict $utemp]} {
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
147 if {$utemp < $wtemp_min_val} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
148 set wtemp_min_key $ukey
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
149 set wtemp_min_val $utemp
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
150 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
151 if {$utemp > $wtemp_max_val} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
152 set wtemp_max_key $ukey
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
153 set wtemp_max_val $utemp
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
154 }
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 close $ufile
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
159
334
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
160 # Store min/max
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
161 if {$wtemp_min_key != "" && $wtemp_max_key != ""} {
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
162 set weather_data(w_min) $weather_data($wtemp_min_key)
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
163 set weather_data(w_max) $weather_data($wtemp_max_key)
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
164 } else {
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
165 set weather_data(w_min) 0
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
166 set weather_data(w_max) 0
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
167 }
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 } else {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 weather_log "Could not open data file: $uerrmsg"
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 #-------------------------------------------------------------------------
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
175 # Weather data update loop
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 proc weather_exec {} {
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
177 global weather_check_period weather_running
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 # Perform update
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 weather_update
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 # Schedule next update
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 set weather_running [clock seconds]
173
3ea14355e2d4 weather: Fix a silly bug in the weather data update loop. :S
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
184 timer $weather_check_period weather_exec
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 #-------------------------------------------------------------------------
535
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
189 # Translate wind direction compass degree to name
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
190 proc weather_get_wind_direction {uangle} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
191 global weather_msg_wind_directions
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
192
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
193 # If the data was not got, return empty value
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
194 if {$uangle == ""} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
195 return ""
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
196 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
197
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
198 # Calculate index to array of 8 compass direction names based on the angle we have
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
199 set uvalue [expr int(floor(fmod($uangle + 45.0/2, 360.0) / 45.0))]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
200 if {$uvalue >= 0 && $uvalue < [llength $weather_msg_wind_directions]} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
201 return [lindex $weather_msg_wind_directions $uvalue]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
202 } else {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
203 return "ERROR ($udir)"
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
204 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
205 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
206
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
207
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
208 proc weather_get_raw_table_value {utable uvalue} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
209 # If the data was not got, return empty value
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
210 if {$uvalue == "" || $uvalue == "NaN"} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
211 return ""
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
212 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
213
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
214 return "[expr int($uvalue) + 1]/[llength $utable]"
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
215 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
216
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
217
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
218 # "Translate" a straight table index (0-N) to table value
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
219 proc weather_get_table_value {utable uvalue} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
220 # If the data was not got, return empty value
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
221 if {$uvalue == "" || $uvalue == "NaN"} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
222 return ""
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
223 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
224
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
225 set uvalue [expr int($uvalue)]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
226 set ulen [llength $utable]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
227 if {$uvalue >= 0 && $uvalue < $ulen} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
228 return [lindex $utable $uvalue]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
229 } else {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
230 return "ERROR ($uvalue)"
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
231 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
232 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
233
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
234
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
235 # Produce one location of weather data as a string
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
236 proc weather_get_str {udata umsg} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
237 global weather_msg_cloudiness
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
238 global weather_msg_precipitation
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
239
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
240 array unset uvals
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
241 set uvals(station) [lindex $udata 0]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
242 set uvals(type) [lindex $udata 1]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
243 set uvals(c_lat) [lindex $udata 2]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
244 set uvals(c_lng) [lindex $udata 3]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
245 set uvals(c_height) [lindex $udata 4]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
246 set uvals(vtime) [lindex $udata 5]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
247 set uvals(temp) [lindex $udata 6]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
248 set uvals(humidity) [lindex $udata 7]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
249 set uvals(wind_speed) [lindex $udata 8]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
250 set uvals(wind_direction) [weather_get_wind_direction [lindex $udata 9]]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
251 set uvals(wind_direction_deg) [lindex $udata 9]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
252 set uvals(cloudiness) [weather_get_table_value $weather_msg_cloudiness [lindex $udata 10]]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
253 set uvals(cloudiness_val) [weather_get_raw_table_value $weather_msg_cloudiness [lindex $udata 10]]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
254 set uvals(road_surface_temp) [lindex $udata 11]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
255 set uvals(precipitation) [lindex $udata 12]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
256 set uvals(visibility) [lindex $udata 13]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
257 set uvals(precipitation2) [weather_get_table_value $weather_msg_precipitation [lindex $udata 14]]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
258 set uvals(precipitation_val) [weather_get_raw_table_value $weather_msg_precipitation [lindex $udata 14]]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
259
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
260 if {[expr [clock seconds] - $uvals(vtime)] < 3600} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
261 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M"]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
262 } else {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
263 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M (%d.%m.%Y)"]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
264 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
265
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
266 set astr ""
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
267 foreach aitem $umsg {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
268 set atmp $aitem
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
269 foreach {akey aval} [array get uvals] {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
270 if {$aval != ""} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
271 set atmp [string map [list "@${akey}@" $aval] $atmp]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
272 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
273 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
274 if {$atmp != $aitem || [string first "@" $aitem] < 0} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
275 append astr $atmp
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
276 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
277 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
278
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
279 return $astr
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
280 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
281
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
282
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
283 # Get data by location key
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
284 proc weather_get_by_key {ukey} {
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
285 global weather_data weather_msg_result
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
286 return [weather_get_str $weather_data($ukey) $weather_msg_result]
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
287 }
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
288
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
289
edbc0190e82a weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents: 499
diff changeset
290 #-------------------------------------------------------------------------
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
291 # Script initialization
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
292 #-------------------------------------------------------------------------
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
293
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 if {![info exists weather_data]} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 array set weather_data {}
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
298 if {![info exists weather_aliases]} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
299 array set weather_aliases {}
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
300 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
301
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 if {[info exists weather_running]} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 set weather_last [expr [clock seconds] - $weather_running]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 } else {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 set weather_last -1
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
308 weather_log "Loading aliases."
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
309 weather_load_aliases
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
310
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 if {$weather_last < 0 || $weather_last > [expr $weather_check_period * 60]} {
364
3b67c66fe0dc weather: Add debugging prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 360
diff changeset
312 weather_log "Starting weather update timer."
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 weather_exec
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 } else {
364
3b67c66fe0dc weather: Add debugging prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 360
diff changeset
315 weather_log "Continuing weather updates."
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 weather_update
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
319
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 proc weather_cmd {unick uhand uchan uargs upublic} {
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
322 global weather_default_locations weather_data weather_max_results weather_aliases
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
323 global weather_msg_usage_full weather_msg_usage_def_set weather_msg_user_not_known
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 global weather_msg_no_results weather_msg_no_data_for_location
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
325 global weather_msg_usage_alias weather_msg_usage_unalias weather_msg_defloc
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
326 global weather_msg_aliased weather_msg_unaliased weather_msg_no_access
174
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
327 global weather_msg_def_set weather_msg_def_not_set weather_msg_aliases
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
328 global weather_msg_usage_stations weather_msg_stations weather_msg_list_station
430
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
329 global weather_msg_list_nearest weather_msg_usage_nearest weather_msg_usage_nearest_invalid
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
330 global weather_msg_nearest_stations weather_msg_result
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
331
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 # Check and handle arguments
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 set rarglist [::textutil::split::splitx $uargs {\s+}]
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
334 set rcmd [lindex $rarglist 0]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
336 if {$rcmd == "?" || $rcmd == "help" || $rcmd == "apua"} {
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
337 weather_usage $upublic $unick $uchan $weather_msg_usage_full
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 return 0
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 }
217
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
340
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
341 if {$rcmd == "asemat" || $rcmd == "stations"} {
217
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
342 # List stations/locations matching the given pattern
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
343 if {[llength $rarglist] < 2} {
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
344 weather_usage $upublic $unick $uchan $weather_msg_usage_stations
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
345 return 0
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
346 }
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
347
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
348 set rmatch [join [lrange $rarglist 1 end] " "]
217
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
349 set result {}
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
350
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
351 foreach {ukey uvalue} [array get weather_data] {
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
352 if {![string match "w_*" $ukey] && [string match -nocase "*${rmatch}*" $ukey]} {
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
353 lappend result [weather_get_str $uvalue $weather_msg_list_station]
217
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
354 }
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
355 }
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
356
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
357 set res [join $result " ; "]
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
358 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res]
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
359 return 0
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
360 } elseif {$rcmd == "lahin" || $rcmd == "lähin" || $rcmd == "closest" || $rcmd == "nearest"} {
430
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
361 # List stations nearest to given coordinates
454
112f8afa2f04 weather: Improve "nearest" sub-command argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 453
diff changeset
362 set qargs [join [lrange $rarglist 1 end] ""]
455
511f1b28c8d1 weather: Improve parsing of GPS coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
363 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} {
430
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
364 weather_usage $upublic $unick $uchan $weather_msg_usage_nearest
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
365 return 0
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
366 }
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
367
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
368 # Check argument types
437
e28c3347a948 Backed out changeset 3c816fdc302f "great circle distance", for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 436
diff changeset
369 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} {
430
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
370 weather_msg $upublic $unick $uchan $weather_msg_usage_nearest_invalid
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
371 return 0
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
372 }
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
373
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
374 # Calculate distances between given coordinates for each location
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
375 set result {}
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
376 foreach {ukey uvalue} [array get weather_data] {
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
377 if {![string match "w_*" $ukey]} {
437
e28c3347a948 Backed out changeset 3c816fdc302f "great circle distance", for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 436
diff changeset
378 set delta_lat [expr {$d_lat - [lindex $uvalue 2]}]
e28c3347a948 Backed out changeset 3c816fdc302f "great circle distance", for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 436
diff changeset
379 set delta_lng [expr {$d_lng - [lindex $uvalue 3]}]
e28c3347a948 Backed out changeset 3c816fdc302f "great circle distance", for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 436
diff changeset
380 set dist [expr { sqrt($delta_lat * $delta_lat + $delta_lng * $delta_lng) }]
430
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
381 lappend result [list $ukey $dist]
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
382 }
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
383 }
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
384
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
385 # Sort the list by distance
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
386 set usorted [lsort -real -index 1 $result]
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
387
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
388 # Create a result list for few best/first matches
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
389 set uresult {}
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
390 foreach {uval} [lrange $usorted 0 2] {
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
391 lappend uresult [weather_get_str $weather_data([lindex $uval 0]) $weather_msg_list_nearest]
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
392 }
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
393
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
394 # Print out the result
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
395 set res [join $uresult " ; "]
437
e28c3347a948 Backed out changeset 3c816fdc302f "great circle distance", for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 436
diff changeset
396 weather_msg $upublic $unick $uchan $weather_msg_nearest_stations [list $d_lat $d_lng $res]
430
8efbb045d44d weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
397 return 0
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
398 } elseif {$rcmd == "vakio" || $rcmd == "default" || $rcmd == "vakiot" || $rcmd == "defaults"} {
217
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
399 # List or set the default weather station name patterns for this user
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
400
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
401 # Access check
536
1044fbacb8a7 weather: Use utl_valid_user instead of weather_valid_user.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
402 if {![utl_valid_user $uhand]} {
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
403 weather_msg $upublic $unick $uchan $weather_msg_user_not_known
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
404 return 0
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
405 }
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
406
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
407 if {[llength $rarglist] == 1} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
408 set lista [getuser $uhand XTRA "weather_locations"]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
409 if {$lista == "" || $lista == "{}"} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
410 weather_msg $upublic $unick $uchan $weather_msg_def_not_set [list $uhand]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
411 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
412 set lista [join [split $lista ";"] " ; "]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
413 weather_msg $upublic $unick $uchan $weather_msg_defloc [list $uhand $lista]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
414 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
415 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
416 # Split the list of desired locations
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
417 set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*\;\s*}]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
418 set nlist [lsearch -all -inline -not -exact $qlist ""]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
419
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
420 if {[llength $nlist] > 0} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
421 weather_msg $upublic $unick $uchan $weather_msg_def_set [list [join $nlist " ; "]]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
422 setuser $uhand XTRA "weather_locations" [join $nlist ";"]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
423 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
424 weather_usage $upublic $unick $uchan $weather_msg_usage_def_set
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
425 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
426 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
427 return 0
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
428 } elseif {$rcmd == "alias"} {
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
429 # Alias a string to another, only certain users have access (+n flag)
536
1044fbacb8a7 weather: Use utl_valid_user instead of weather_valid_user.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
430 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} {
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
431 weather_msg $upublic $unick $uchan $weather_msg_no_access
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 return 0
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
435 set qlist [::textutil::split::splitx [join [lrange $rarglist 1 end] " "] {\s*=\s*}]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 set nlist [lsearch -all -inline -not -exact $qlist ""]
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
437 if {[llength $nlist] < 2} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
438 weather_usage $upublic $unick $uchan $weather_msg_usage_alias
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
439 return 0
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
440 }
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
441
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
442 set ualias [lindex $nlist 0]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
443 set uname [lindex $nlist 1]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
444 set weather_aliases($ualias) $uname
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
445 weather_msg $upublic $unick $uchan $weather_msg_aliased [list $ualias $uname]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
447 weather_save_aliases
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 return 0
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
449 } elseif {$rcmd == "unalias"} {
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
450 # Remove one alias, only certain users have access (+n flag)
536
1044fbacb8a7 weather: Use utl_valid_user instead of weather_valid_user.
Matti Hamalainen <ccr@tnsp.org>
parents: 535
diff changeset
451 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} {
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
452 weather_msg $upublic $unick $uchan $weather_msg_no_access
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
453 return 0
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
454 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
455
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
456 if {[llength $rarglist] < 2} {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
457 weather_usage $upublic $unick $uchan $weather_msg_usage_unalias
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
458 return 0
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
459 }
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
460
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
461 set ualias [lindex $rarglist 1]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
462 unset weather_aliases($ualias)
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
463 weather_msg $upublic $unick $uchan $weather_msg_unaliased [list $ualias]
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
464
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
465 weather_save_aliases
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
466 return 0
453
c69368f97c10 weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
467 } elseif {$rcmd == "list"} {
174
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
468 # List all currently defined aliases
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
469 set ulist {}
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
470 foreach {ukey uvalue} [array get weather_aliases] {
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
471 lappend ulist "\002'$ukey' = '$uvalue'\002"
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
472 }
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
473 weather_msg $upublic $unick $uchan $weather_msg_aliases [list [join $ulist ", "]]
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
474 return 0
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
475 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
476
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 # Get args or default location(s)
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 set rargs [join $rarglist " "]
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
479 if {$rargs == "" && $uhand != "" && $uhand != "{}" && $uhand != "*"} {
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 set rargs [getuser $uhand XTRA "weather_locations"]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 }
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
482 if {$rargs == ""} {
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 set rargs $weather_default_locations
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 # Handle argument list
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
487 set nresults 0
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 set rarglist [::textutil::split::splitx $rargs "\s*\;\s*"]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 foreach rarg $rarglist {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 if {$rarg == "min"} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 # Min temp
279
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
492 set umin [weather_get_by_key "w_min"]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 weather_msg $upublic $unick $uchan "Min: $umin"
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
494 incr nresults
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 } elseif {$rarg == "max"} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 # Max temp
279
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
497 set umax [weather_get_by_key "w_max"]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 weather_msg $upublic $unick $uchan "Max: $umax"
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
499 incr nresults
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 } elseif {$rarg == "minmax" || $rarg == "min max" || $rarg == "maxmin" || $rarg == "max min"} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 # Min & Max temps
279
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
502 set umin [weather_get_by_key "w_min"]
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
503 set umax [weather_get_by_key "w_max"]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 weather_msg $upublic $unick $uchan "Min: $umin | Max: $umax"
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
505 incr nresults
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 } else {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 # Location match
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 set ufound 0
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
509 set rarg [weather_get_alias $rarg]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 foreach {ukey uvalue} [array get weather_data] {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 if {[llength $uvalue] > 0} {
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
513 weather_msg $upublic $unick $uchan [weather_get_str $uvalue $weather_msg_result]
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
514 incr nresults
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 } else {
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
516 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 incr ufound
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 }
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
520
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
521 # Check for results limit
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
522 if {$nresults >= $weather_max_results} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
523 return 0
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
524 }
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 }
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
526
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 if {$ufound == 0} {
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
528 weather_msg $upublic $unick $uchan $weather_msg_no_data_for_location [list $rarg]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 }
421
0f7524550aa2 weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
531
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
532 # Check for results limit
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
533 if {$nresults >= $weather_max_results} {
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
534 return 0
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
535 }
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 return 0
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 proc weather_cmd_pub {unick uhost uhand uchan uargs} {
220
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
544 global weather_channels
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
545
344
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
546 if {[utl_match_delim_list $weather_channels $uchan]} {
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
547 return [weather_cmd $unick $uhand $uchan $uargs 1]
220
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
548 }
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
549
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
550 return 0
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 proc weather_cmd_msg {unick uhost uhand uargs} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 return [weather_cmd $unick $uhand "PRIV" $uargs 0]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 # end of script