Mercurial > hg > egg-tcls
annotate weather.tcl @ 335:e6473e7083aa
weather: Bump version.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 Sep 2015 14:39:02 +0300 |
parents | 088bb2621595 |
children | 25fc5a2b42ae |
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 # |
335 | 3 # Weather v0.9.1 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
233
dc1afa011883
weather: Bump version, copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
4 # (C) Copyright 2014-2015 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 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 ########################################################################## |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 # 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
|
21 ########################################################################## |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 set weather_name "Weather" |
335 | 23 set weather_version "0.9.1" |
184 | 24 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 ### Initialization messages |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 package require textutil::split |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 set weather_message "$weather_name v$weather_version by ccr/TNSP" |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 putlog "$weather_message" |
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 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 #------------------------------------------------------------------------- |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 proc weather_log {arg} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 global weather_logmsg weather_name |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 if {$weather_logmsg != 0} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 putlog "$weather_name: $arg" |
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 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
41 proc weather_msg_do {apublic anick achan amsg} { |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 global weather_preferredmsg |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 if {$apublic == 1} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 putserv "$weather_preferredmsg $achan :$amsg" |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 } else { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 putserv "$weather_preferredmsg $anick :$amsg" |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
51 proc weather_msg {apublic anick achan amsg {aargs {}}} { |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
52 set narg 1 |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
53 foreach marg $aargs { |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
54 set amsg [string map [list "%$narg" $marg] $amsg] |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
55 incr narg |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
56 } |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
57 weather_msg_do $apublic $anick $achan $amsg |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
58 } |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
59 |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
60 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
61 proc weather_usage {apublic anick achan amsg} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
62 global weather_msg_usage_prefix_1 weather_msg_usage_prefix_2 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
63 set nline 0 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
64 foreach aline [split $amsg "\n"] { |
203
28ee3578a6d1
Weather: Add support for usage messages without default prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
65 if {[string range $aline 0 1] == ":"} { |
28ee3578a6d1
Weather: Add support for usage messages without default prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
66 weather_msg_do $apublic $anick $achan $aline |
28ee3578a6d1
Weather: Add support for usage messages without default prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
67 } elseif {$nline == 0} { |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
68 weather_msg_do $apublic $anick $achan "$weather_msg_usage_prefix_1$aline" |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
69 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
70 weather_msg_do $apublic $anick $achan "$weather_msg_usage_prefix_2$aline" |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
71 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
72 incr nline |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
73 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
74 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
75 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
76 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 proc weather_ctime {utime} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 return [clock format $utime -format "%H:%M"] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
82 proc weather_valid_user {uhand} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
83 if {$uhand != "" && $uhand != "{}" && $uhand != "*"} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
84 return 1 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
85 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
86 return 0 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
87 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
88 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
89 |
163
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 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
|
92 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
|
93 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
94 # Create dict |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
95 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
|
96 array set weather_aliases {} |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
97 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
98 # Read datafile |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
99 if {![catch {set ufile [open $weather_aliasfile 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
106 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
107 close $ufile |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
108 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
109 weather_log "Could not open data file: $uerrmsg" |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
110 } |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
111 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
112 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
113 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
114 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
|
115 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
|
116 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
121 close $ufile |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
122 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
123 weather_log "Could not open data file: $uerrmsg" |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
124 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
125 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
126 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
127 |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
128 # 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
135 return $uname |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
136 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
137 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
138 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
139 #------------------------------------------------------------------------- |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
140 # Produce one location of weather data as a string |
280 | 141 proc weather_get_data {udata ukey} { |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
142 global weather_msg_result |
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
143 |
287
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
144 # Set data to array |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
145 array unset uvals |
287
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
146 set uvals(station) [lindex $udata 0] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
147 set uvals(type) [lindex $udata 1] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
148 set uvals(vtime) [lindex $udata 2] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
149 set uvals(ctime) [weather_ctime [lindex $udata 2]] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
150 set uvals(temp) [lindex $udata 3] |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
151 |
238
a1d6e2d8789e
Add new data from FMI service and change datafile format.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
152 if {[lindex $udata 1] == 0} { |
287
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
153 set uvals(weather1) [lindex $udata 5] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
154 set uvals(weather2) [lindex $udata 6] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
155 set uvals(road_temp) [lindex $udata 4] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
156 } else { |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
157 set uvals(humidity) [lindex $udata 4] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
158 set uvals(wind_speed) [lindex $udata 5] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
159 set uvals(cloud_cover) [lindex $udata 6] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
160 } |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
161 |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
162 # Transform the format list |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
163 set astr "" |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
164 foreach aitem $weather_msg_result { |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
165 set atmp $aitem |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
166 foreach {akey aval} [array get uvals] { |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
167 if {$aval != ""} { |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
168 set atmp [string map [list "@${akey}@" $aval] $atmp] |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
169 } |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
170 } |
287
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
171 if {$atmp != $aitem} { |
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
172 append astr $atmp |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
173 } |
238
a1d6e2d8789e
Add new data from FMI service and change datafile format.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
174 } |
285
259f093c9503
weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
175 |
287
748c6b44f572
weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
176 return "$astr." |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
177 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
178 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
179 |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
180 # Get data by location key |
279
f6dc673adfa1
weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
181 proc weather_get_by_key {ukey} { |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
182 global weather_data |
279
f6dc673adfa1
weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
183 return [weather_get_data $weather_data($ukey) $ukey] |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
184 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
185 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
186 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 #------------------------------------------------------------------------- |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 proc weather_update {} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 global weather_datafile weather_data |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 |
172
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
191 # 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
|
192 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
|
193 # Create dict |
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
194 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
|
195 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
|
196 |
172
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 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
|
201 |
2c89e47739e8
weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
202 # Read in the data |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 while {![eof $ufile]} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 gets $ufile uline |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 set udata [split $uline "|"] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 if {[llength $udata] > 0} { |
201 | 207 set utemp [lindex $udata 3] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 set ukey [lindex $udata 0] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 set weather_data($ukey) $udata |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
212 if {[string is double -strict $utemp]} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
213 if {$utemp < $wtemp_min_val} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
214 set wtemp_min_key $ukey |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
215 set wtemp_min_val $utemp |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
216 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
217 if {$utemp > $wtemp_max_val} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
218 set wtemp_max_key $ukey |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
219 set wtemp_max_val $utemp |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
220 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 close $ufile |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 |
334
088bb2621595
weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
226 # Store min/max |
088bb2621595
weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 } else { |
088bb2621595
weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
231 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
|
232 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
|
233 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 } else { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 weather_log "Could not open data file: $uerrmsg" |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 #------------------------------------------------------------------------- |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
241 # Weather data update loop |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 proc weather_exec {} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 global weather_check_period weather_running |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 # Perform update |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 weather_update |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 # Schedule next update |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 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
|
250 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
|
251 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 #------------------------------------------------------------------------- |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
255 # Script initialization |
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
256 #------------------------------------------------------------------------- |
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
257 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 if {![info exists weather_data]} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 array set weather_data {} |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
262 if {![info exists weather_aliases]} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
263 array set weather_aliases {} |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
264 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
265 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 if {[info exists weather_running]} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 set weather_last [expr [clock seconds] - $weather_running] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 } else { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 set weather_last -1 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
272 weather_log "Loading aliases." |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
273 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
|
274 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 if {$weather_last < 0 || $weather_last > [expr $weather_check_period * 60]} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 weather_log "Starting weather update." |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 weather_exec |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 } else { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 weather_update |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
282 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 #------------------------------------------------------------------------- |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 proc weather_cmd {unick uhand uchan uargs upublic} { |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
285 global weather_default_locations weather_data weather_max_results weather_aliases |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
286 global weather_msg_usage_full weather_msg_usage_def_set weather_msg_user_not_known |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 global weather_msg_no_results weather_msg_no_data_for_location |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
288 global weather_msg_usage_alias weather_msg_usage_unalias weather_msg_defloc |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
289 global weather_msg_aliased weather_msg_unaliased weather_msg_no_access |
174
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
290 global weather_msg_def_set weather_msg_def_not_set weather_msg_aliases |
217
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
291 global weather_msg_usage_stations weather_msg_stations |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
292 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 # Check and handle arguments |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 set rarglist [::textutil::split::splitx $uargs {\s+}] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 set rarg [lindex $rarglist 0] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 if {$rarg == "?" || $rarg == "help" || $rarg == "apua"} { |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
298 weather_usage $upublic $unick $uchan "$weather_msg_usage_full" |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 return 0 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 } |
217
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
301 |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
302 if {$rarg == "asemat" || $rarg == "stations"} { |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
303 # 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
|
304 if {[llength $rarglist] < 2} { |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
305 weather_usage $upublic $unick $uchan $weather_msg_usage_stations |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
306 return 0 |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
307 } |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
308 |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
309 set rarg [join [lrange $rarglist 1 end] " "] |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
310 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
|
311 |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
312 foreach {ukey uvalue} [array get weather_data] { |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
313 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} { |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
314 lappend result $ukey |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
315 } |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
316 } |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
317 |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
318 set res [join $result " ; "] |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
319 weather_msg $upublic $unick $uchan $weather_msg_stations [list $res] |
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
320 return 0 |
273
38a5bce4b078
weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
248
diff
changeset
|
321 } elseif {$rarg == "vakio" || $rarg == "default" || $rarg == "vakiot" || $rarg == "defaults"} { |
217
67018e353536
weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
322 # 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
|
323 |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
324 # Access check |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
325 if {![weather_valid_user $uhand]} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
326 weather_msg $upublic $unick $uchan $weather_msg_user_not_known |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
327 return 0 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
328 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
329 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
330 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
|
331 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
|
332 if {$lista == "" || $lista == "{}"} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
333 weather_msg $upublic $unick $uchan $weather_msg_def_not_set [list $uhand] |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
334 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
335 set lista [join [split $lista ";"] " ; "] |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
336 weather_msg $upublic $unick $uchan $weather_msg_defloc [list $uhand $lista] |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
337 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
338 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
339 # 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
|
340 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
|
341 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
|
342 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
343 if {[llength $nlist] > 0} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
344 weather_msg $upublic $unick $uchan $weather_msg_def_set [list [join $nlist " ; "]] |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
345 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
|
346 } else { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
347 weather_usage $upublic $unick $uchan $weather_msg_usage_def_set |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
348 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
349 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
350 return 0 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
351 } elseif {$rarg == "alias"} { |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
352 # Alias a string to another, only certain users have access (+n flag) |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
353 if {![weather_valid_user $uhand] || ![matchattr $uhand n]} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
354 weather_msg $upublic $unick $uchan $weather_msg_no_access |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 return 0 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
358 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
|
359 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
|
360 if {[llength $nlist] < 2} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
361 weather_usage $upublic $unick $uchan $weather_msg_usage_alias |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
362 return 0 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
363 } |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
364 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
365 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
|
366 set uname [lindex $nlist 1] |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
367 set weather_aliases($ualias) $uname |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
368 weather_msg $upublic $unick $uchan $weather_msg_aliased [list $ualias $uname] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
370 weather_save_aliases |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 return 0 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
372 } elseif {$rarg == "unalias"} { |
171
5434903331df
weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
167
diff
changeset
|
373 # Remove one alias, only certain users have access (+n flag) |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
374 if {![weather_valid_user $uhand] || ![matchattr $uhand n]} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
375 weather_msg $upublic $unick $uchan $weather_msg_no_access |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
376 return 0 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
377 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
378 |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
379 if {[llength $rarglist] < 2} { |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
380 weather_usage $upublic $unick $uchan $weather_msg_usage_unalias |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
381 return 0 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
382 } |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
383 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
384 set ualias [lindex $rarglist 1] |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
385 unset weather_aliases($ualias) |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
386 weather_msg $upublic $unick $uchan $weather_msg_unaliased [list $ualias] |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
387 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
388 weather_save_aliases |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
389 return 0 |
174
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
390 } elseif {$rarg == "list"} { |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
391 # List all currently defined aliases |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
392 set ulist {} |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
393 foreach {ukey uvalue} [array get weather_aliases] { |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
394 lappend ulist "\002'$ukey' = '$uvalue'\002" |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
395 } |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
396 weather_msg $upublic $unick $uchan $weather_msg_aliases [list [join $ulist ", "]] |
d94be9a1be6a
weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
397 return 0 |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
398 } |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
399 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 # 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
|
401 set rargs [join $rarglist " "] |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
402 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
|
403 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
|
404 } |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
405 if {$rargs == ""} { |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 set rargs $weather_default_locations |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 # Handle argument list |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
410 set nresults 0 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 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
|
412 foreach rarg $rarglist { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 if {$rarg == "min"} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 # Min temp |
279
f6dc673adfa1
weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
415 set umin [weather_get_by_key "w_min"] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 weather_msg $upublic $unick $uchan "Min: $umin" |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
417 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 } elseif {$rarg == "max"} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 # Max temp |
279
f6dc673adfa1
weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
420 set umax [weather_get_by_key "w_max"] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 weather_msg $upublic $unick $uchan "Max: $umax" |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
422 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 } 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
|
424 # Min & Max temps |
279
f6dc673adfa1
weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
425 set umin [weather_get_by_key "w_min"] |
f6dc673adfa1
weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
426 set umax [weather_get_by_key "w_max"] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
427 weather_msg $upublic $unick $uchan "Min: $umin | Max: $umax" |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
428 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 } else { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 # Location match |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 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
|
435 if {[llength $uvalue] > 0} { |
279
f6dc673adfa1
weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
436 weather_msg $upublic $unick $uchan [weather_get_data $uvalue $ukey] |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
437 incr nresults |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 } else { |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
439 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 incr ufound |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 } |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
443 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
444 # Check for results limit |
161
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
445 if {$nresults >= $weather_max_results} { |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
446 return 0 |
2c9db9a29429
weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
447 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 if {$ufound == 0} { |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
451 weather_msg $upublic $unick $uchan $weather_msg_no_data_for_location [list $rarg] |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
452 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 } |
163
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
454 |
bee5cd89d41c
weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
455 # Check for results limit |
156
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
456 if {$nresults >= $weather_max_results} { |
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
457 return 0 |
a1f4c163e48c
weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
458 } |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
460 return 0 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
461 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
462 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
464 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
465 #------------------------------------------------------------------------- |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
466 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
|
467 global weather_channels |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
468 |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
469 foreach akey [split $weather_channels ";"] { |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
470 if {[string match $akey $uchan]} { |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
471 return [weather_cmd $unick $uhand $uchan $uargs 1] |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
472 } |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
473 } |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
474 |
03579553233b
weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
475 return 0 |
153
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
476 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 #------------------------------------------------------------------------- |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
479 proc weather_cmd_msg {unick uhost uhand uargs} { |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
480 return [weather_cmd $unick $uhand "PRIV" $uargs 0] |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
481 } |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 |
8b888a9f07df
New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 # end of script |