Mercurial > hg > egg-tcls
annotate weather.tcl @ 622:84a30765baa1
tj: Add ability for administrator users to 'list' other peoples TJs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 10 Feb 2021 15:27:10 +0200 |
parents | a09401d4ac8c |
children | 2723be85343a |
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 # |
602 | 3 # Weather v2.1.0 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
578 | 4 # (C) Copyright 2014-2021 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 | 6 # Requires data fetcher to be run as a cronjob, see fetch_weather.pl |
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 ########################################################################## |
555 | 25 package require textutil::split |
26 | |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 set weather_name "Weather" |
602 | 28 set weather_message "$weather_name v2.1.0 (C) 2014-2021 ccr/TNSP" |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 #------------------------------------------------------------------------- |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
32 ### Utility functions |
555 | 33 proc weather_log {umsg} { |
550
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
34 global weather_log_enable weather_name |
85fe3bc36307
Rename *_logmsg settings to *_log_enable.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
35 if {$weather_log_enable != 0} { |
595 | 36 putlog "${weather_name}: $umsg" |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
41 proc weather_qm {uid} { |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
42 global weather_messages |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
43 |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
44 if {[info exists weather_messages($uid)]} { |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
45 return $weather_messages($uid) |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
46 } else { |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
47 return $uid |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
48 } |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
49 } |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
50 |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
51 |
548 | 52 proc weather_smsg {apublic anick achan amsg {aargs {}}} { |
562
15bc88a1477a
weather: Add setting weather_cmd_name for specifying the command name used for help texts.
Matti Hamalainen <ccr@tnsp.org>
parents:
558
diff
changeset
|
53 global weather_preferredmsg weather_cmd_name |
15bc88a1477a
weather: Add setting weather_cmd_name for specifying the command name used for help texts.
Matti Hamalainen <ccr@tnsp.org>
parents:
558
diff
changeset
|
54 set amsg [string map [list "@cmd@" $weather_cmd_name] $amsg] |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
55 utl_msg_args $weather_preferredmsg $apublic $anick $achan $amsg $aargs |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
56 } |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
57 |
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
58 |
548 | 59 proc weather_msg {apublic anick achan aid {aargs {}}} { |
60 weather_smsg $apublic $anick $achan [weather_qm $aid] $aargs | |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
61 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
62 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
63 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
64 #------------------------------------------------------------------------- |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
65 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
|
66 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
|
67 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
68 # Create dict |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
69 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
|
70 array set weather_aliases {} |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
71 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
72 # Read datafile |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
80 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
81 close $ufile |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
82 } else { |
567 | 83 weather_log "Could not open data file: ${uerrmsg}" |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
84 } |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
85 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
86 |
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 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
|
89 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
|
90 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
95 close $ufile |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
96 } else { |
567 | 97 weather_log "Could not open data file: ${uerrmsg}" |
163
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 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
100 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
101 |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
102 # 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
109 return $uname |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
110 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
111 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
112 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 #------------------------------------------------------------------------- |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 proc weather_update {} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 global weather_datafile weather_data |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 |
172
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
117 # 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
|
118 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
|
119 # Create dict |
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
120 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
|
121 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
|
122 |
172
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 |
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
128 # Read in the data |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 while {![eof $ufile]} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 gets $ufile uline |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 set udata [split $uline "|"] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 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
|
133 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
|
134 set ukey [lindex $udata 0] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 set weather_data($ukey) $udata |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
138 if {[string is double -strict $utemp]} { |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
139 if {$utemp < $wtemp_min_val} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
140 set wtemp_min_key $ukey |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
141 set wtemp_min_val $utemp |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
142 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
143 if {$utemp > $wtemp_max_val} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
144 set wtemp_max_key $ukey |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
145 set wtemp_max_val $utemp |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
146 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 close $ufile |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
151 |
334
088bb2621595
weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
152 # Store min/max |
088bb2621595
weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 } else { |
088bb2621595
weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
157 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
|
158 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
|
159 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 } else { |
567 | 161 weather_log "Could not open data file: ${uerrmsg}" |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 #------------------------------------------------------------------------- |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
167 # Weather data update loop |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 proc weather_exec {} { |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
169 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
|
170 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 # Perform update |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 weather_update |
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 # Schedule next update |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 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
|
176 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
|
177 } |
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 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 #------------------------------------------------------------------------- |
535
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
181 # 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
|
182 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
|
183 global weather_msg_wind_directions |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
184 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
185 # 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
|
186 if {$uangle == ""} { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
187 return "" |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
188 } |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
189 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
190 # 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
|
191 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
|
192 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
|
193 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
|
194 } else { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
195 return "ERROR ($udir)" |
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 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
199 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
200 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
|
201 # 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
|
202 if {$uvalue == "" || $uvalue == "NaN"} { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
203 return "" |
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 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
|
207 } |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
208 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
209 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
210 # "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
|
211 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
|
212 # 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
|
213 if {$uvalue == "" || $uvalue == "NaN"} { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
214 return "" |
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 set uvalue [expr int($uvalue)] |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
218 set ulen [llength $utable] |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
219 if {$uvalue >= 0 && $uvalue < $ulen} { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
220 return [lindex $utable $uvalue] |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
221 } else { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
222 return "ERROR ($uvalue)" |
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 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
226 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
227 # 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
|
228 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
|
229 global weather_msg_cloudiness |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
230 global weather_msg_precipitation |
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 array unset uvals |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
252 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
|
253 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
|
254 } else { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
255 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
|
256 } |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
257 |
569
1fbee4891dbc
weather: Add kludge to always have "value" for "temp" token.
Matti Hamalainen <ccr@tnsp.org>
parents:
568
diff
changeset
|
258 # Kludge for always having a value for "temp" |
1fbee4891dbc
weather: Add kludge to always have "value" for "temp" token.
Matti Hamalainen <ccr@tnsp.org>
parents:
568
diff
changeset
|
259 if {$uvals(temp) == ""} { set uvals(temp) "???" } |
1fbee4891dbc
weather: Add kludge to always have "value" for "temp" token.
Matti Hamalainen <ccr@tnsp.org>
parents:
568
diff
changeset
|
260 |
535
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
261 set astr "" |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
262 foreach aitem $umsg { |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
263 set atmp $aitem |
568
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
264 set aok 1 |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
265 |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
266 # Map tokens to values if they are set |
535
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
267 foreach {akey aval} [array get uvals] { |
568
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
268 if {[string match "*@${akey}@*" $atmp]} { |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
269 if {$aval != ""} { |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
270 set atmp [string map [list "@${akey}@" $aval] $atmp] |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
271 } else { |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
272 set aok 0 |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
273 } |
535
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
274 } |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
275 } |
568
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
276 |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
277 # Add item to string if all tokens in string were found |
1ef78f020573
weather: All tokens in the weather format string item must have a value for the item to be added to the output string.
Matti Hamalainen <ccr@tnsp.org>
parents:
567
diff
changeset
|
278 if {$aok} { |
535
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
279 append astr $atmp |
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 return $astr |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
284 } |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
285 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
286 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
287 # Get data by location key |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
288 proc weather_get_str_by_key {ukey} { |
535
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
289 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
|
290 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
|
291 } |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
292 |
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
293 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
294 proc weather_cmd_match { uid ustr } { |
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
295 global weather_commands |
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
296 return [utl_cmd_match weather_commands $uid $ustr] |
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
297 } |
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
298 |
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
299 |
535
edbc0190e82a
weather: Move some functions around into more logical location.
Matti Hamalainen <ccr@tnsp.org>
parents:
499
diff
changeset
|
300 #------------------------------------------------------------------------- |
548 | 301 proc weather_cmd {unick $uhost 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
|
302 global weather_default_locations weather_data weather_max_results weather_aliases |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
303 global weather_msg_list_station weather_msg_result weather_messages |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
304 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 # Check and handle arguments |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 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
|
307 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
|
308 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
309 if {[weather_cmd_match "help" $rcmd]} { |
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
310 # Show help |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
311 foreach ukey $weather_messages(help_full) { |
540
3174701325c0
weather: Fixes to the help.
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
312 weather_msg $upublic $unick $uchan $ukey |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
313 } |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
314 return 1 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
315 } elseif {[weather_cmd_match "stations" $rcmd]} { |
217
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
316 # 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
|
317 if {[llength $rarglist] < 2} { |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
318 weather_msg $upublic $unick $uchan "help_stations" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
319 return 1 |
217
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
320 } |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
321 |
453
c69368f97c10
weather: Rename a variable to be more descriptive.
Matti Hamalainen <ccr@tnsp.org>
parents:
451
diff
changeset
|
322 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
|
323 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
|
324 |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 } |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
329 } |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
330 |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
331 if {[llength $result] > 0} { |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
332 set res "" |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
333 if {[llength $result] > 10} { |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
334 set res [weather_qm "stations_limit"] |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
335 } |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
336 append res [join [lrange $result 0 10] " ; "] |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
337 } else { |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
338 set res [weather_qm "stations_no_matches"] |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
339 } |
544
3b363fd0a60b
weather: Remove duplicated weather_save_aliases call.
Matti Hamalainen <ccr@tnsp.org>
parents:
543
diff
changeset
|
340 |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
341 weather_msg $upublic $unick $uchan "stations_list" [list $res] |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
342 return 1 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
343 } elseif {[weather_cmd_match "nearest" $rcmd]} { |
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
|
344 # List stations nearest to given coordinates |
454
112f8afa2f04
weather: Improve "nearest" sub-command argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
345 set qargs [join [lrange $rarglist 1 end] ""] |
455
511f1b28c8d1
weather: Improve parsing of GPS coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents:
454
diff
changeset
|
346 if {![regexp {@?(\d+|\d+\.\d+|\.\d+)\s*,\s*(\d+|\d+\.\d+|\.\d+)} $qargs -> d_lat d_lng]} { |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
347 weather_msg $upublic $unick $uchan "help_nearest" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
348 return 1 |
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
|
349 } |
8efbb045d44d
weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
350 |
8efbb045d44d
weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
351 # Check argument types |
437
e28c3347a948
Backed out changeset 3c816fdc302f "great circle distance", for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
352 if {![string is double -strict $d_lat] || ![string is double -strict $d_lng]} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
353 weather_msg $upublic $unick $uchan "nearest_invalid" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
354 return 1 |
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
|
355 } |
8efbb045d44d
weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
356 |
8efbb045d44d
weather: Implement searching for nearest of measurement stations based on given lat/long coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
357 # 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 } |
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 # 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
|
369 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
|
370 |
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 # 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
|
372 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
|
373 foreach {uval} [lrange $usorted 0 2] { |
540
3174701325c0
weather: Fixes to the help.
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
374 lappend uresult [weather_get_str $weather_data([lindex $uval 0]) $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
|
375 } |
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 |
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 # 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
|
378 set res [join $uresult " ; "] |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
379 weather_msg $upublic $unick $uchan "nearest_stations" [list $d_lat $d_lng $res] |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
380 return 1 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
381 } elseif {[weather_cmd_match "default" $rcmd]} { |
217
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
382 # 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
|
383 |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
384 # Access check |
536
1044fbacb8a7
weather: Use utl_valid_user instead of weather_valid_user.
Matti Hamalainen <ccr@tnsp.org>
parents:
535
diff
changeset
|
385 if {![utl_valid_user $uhand]} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
386 weather_msg $upublic $unick $uchan "user_not_known" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
387 return 1 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
388 } |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
389 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
390 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
|
391 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
|
392 if {$lista == "" || $lista == "{}"} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
393 weather_msg $upublic $unick $uchan "def_not_set" [list $uhand] |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
394 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
395 set lista [join [split $lista ";"] " ; "] |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
396 weather_msg $upublic $unick $uchan "def_value" [list $uhand $lista] |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
397 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
398 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
399 # 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
|
400 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
|
401 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
|
402 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
403 if {[llength $nlist] > 0} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
404 weather_msg $upublic $unick $uchan "def_set_to" [list [join $nlist " ; "]] |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
405 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
|
406 } else { |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
407 weather_msg $upublic $unick $uchan "help_def_set" |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
408 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
409 } |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
410 return 1 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
411 } elseif {[weather_cmd_match "alias" $rcmd]} { |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
412 # 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
|
413 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
414 weather_msg $upublic $unick $uchan "no_access" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
415 return 1 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
418 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
|
419 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
|
420 if {[llength $nlist] < 2} { |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
421 weather_msg $upublic $unick $uchan "help_alias" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
422 return 1 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
423 } |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
424 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
425 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
|
426 set uname [lindex $nlist 1] |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
427 |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
428 if {[info exists weather_aliases($ualias)]} { |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
429 weather_msg $upublic $unick $uchan "alias_updated" [list $ualias $weather_aliases($ualias) $uname] |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
430 } else { |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
431 weather_msg $upublic $unick $uchan "alias_set" [list $ualias $uname] |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
432 } |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
433 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
434 set weather_aliases($ualias) $uname |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
436 weather_save_aliases |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
437 return 1 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
438 } elseif {[weather_cmd_match "unalias" $rcmd]} { |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
439 # 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
|
440 if {![utl_valid_user $uhand] || ![matchattr $uhand n]} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
441 weather_msg $upublic $unick $uchan "no_access" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
442 return 1 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
443 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
444 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
445 if {[llength $rarglist] < 2} { |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
446 weather_msg $upublic $unick $uchan "help_unalias" |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
447 return 1 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
448 } |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
449 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
450 set ualias [lindex $rarglist 1] |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
451 |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
452 if {![info exists weather_aliases($ualias)]} { |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
453 weather_msg $upublic $unick $uchan "alias_not_exist" [list $ualias] |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
454 return 1 |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
455 } |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
456 |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
457 weather_msg $upublic $unick $uchan "alias_unset" [list $ualias $weather_aliases($ualias)] |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
458 unset weather_aliases($ualias) |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
459 weather_save_aliases |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
460 |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
461 return 1 |
600
90da5691cc81
weather: Use new command matching.
Matti Hamalainen <ccr@tnsp.org>
parents:
595
diff
changeset
|
462 } elseif {[weather_cmd_match "list" $rcmd]} { |
174
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
463 # List all currently defined aliases |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
464 set ulist {} |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
465 set ulistitem [weather_qm "alias_item"] |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
466 set ulistsep [weather_qm "alias_list_sep"] |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
467 |
174
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
468 foreach {ukey uvalue} [array get weather_aliases] { |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
469 lappend ulist [utl_str_map_values $ulistitem [list $ukey $uvalue]] |
174
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
470 } |
543
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
471 |
a513b98f2a37
weather: Improve alias handling and do some work on stations listing.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
472 weather_msg $upublic $unick $uchan "alias_list" [list [join $ulist $ulistsep]] |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
473 return 1 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
474 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
475 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
476 # 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
|
477 set rargs [join $rarglist " "] |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
478 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
|
479 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
|
480 } |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
481 if {$rargs == ""} { |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 set rargs $weather_default_locations |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 } |
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 # Handle argument list |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
486 set nresults 0 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
487 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
|
488 foreach rarg $rarglist { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
489 if {$rarg == "min"} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
490 # Min temp |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
491 weather_msg $upublic $unick $uchan "temp_min" [list [weather_get_str_by_key "w_min"]] |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
492 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
493 } elseif {$rarg == "max"} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
494 # Max temp |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
495 weather_msg $upublic $unick $uchan "temp_max" [list [weather_get_str_by_key "w_max"]] |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
496 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
497 } 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
|
498 # Min & Max temps |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
499 weather_msg $upublic $unick $uchan "temp_minmax" [list [weather_get_str_by_key "w_min"] [weather_get_str_by_key "w_max"]] |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
500 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 } else { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
502 # Location match |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
503 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
|
504 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
|
505 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
|
506 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
|
507 if {[llength $uvalue] > 0} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
508 weather_smsg $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
|
509 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
510 } else { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
511 weather_msg $upublic $unick $uchan "no_results" [list $ukey] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
512 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 incr ufound |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
514 } |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
515 |
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
516 # Check for results limit |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
517 if {$nresults >= $weather_max_results} { |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
518 return 1 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
519 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 } |
421
0f7524550aa2
weather: Cosmetics, stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
419
diff
changeset
|
521 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
522 if {$ufound == 0} { |
538
f07c972e269a
weather: Refactor much of the messages system to match the quotedb one.
Matti Hamalainen <ccr@tnsp.org>
parents:
537
diff
changeset
|
523 weather_msg $upublic $unick $uchan "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
|
524 } |
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 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
527 # Check for results limit |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
528 if {$nresults >= $weather_max_results} { |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
529 return 1 |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
530 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
531 } |
588
dae8f6ad12c2
weather: Fix weather_cmd return values.
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
532 return 1 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
533 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
534 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
535 |
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 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
|
538 global weather_channels |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
539 |
344
25fc5a2b42ae
weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
335
diff
changeset
|
540 if {[utl_match_delim_list $weather_channels $uchan]} { |
548 | 541 return [weather_cmd $unick $uhost $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
|
542 } |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
543 |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
544 return 0 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
545 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
546 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
547 proc weather_cmd_msg {unick uhost uhand uargs} { |
548 | 548 return [weather_cmd $unick $uhost $uhand "PRIV" $uargs 0] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 |
555 | 551 |
552 #------------------------------------------------------------------------- | |
553 # Script initialization | |
554 #------------------------------------------------------------------------- | |
558
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
555 putlog "$weather_message" |
e0ff67318a99
weather: Rename some message ids, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
556 |
555 | 557 |
558 if {![info exists weather_data]} { | |
559 array set weather_data {} | |
560 } | |
561 | |
562 if {![info exists weather_aliases]} { | |
563 array set weather_aliases {} | |
564 } | |
565 | |
566 if {[info exists weather_running]} { | |
567 set weather_last [expr [clock seconds] - $weather_running] | |
568 } else { | |
569 set weather_last -1 | |
570 } | |
571 | |
572 putlog " - Loading aliases." | |
573 weather_load_aliases | |
574 | |
575 if {$weather_last < 0 || $weather_last > [expr $weather_check_period * 60]} { | |
576 putlog " - Starting weather update timer." | |
577 weather_exec | |
578 } else { | |
579 putlog " - Continuing weather updates." | |
580 weather_update | |
581 } | |
582 | |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
583 # end of script |