annotate weather.tcl @ 419:3566fdca974b

weather: Rename a string token.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 08 Jan 2017 00:56:13 +0200
parents e904b453a06a
children 0f7524550aa2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #
415
ff932030a9b3 weather: Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 414
diff changeset
3 # Weather v0.9.5 by Matti 'ccr' Hamalainen <ccr@tnsp.org>
408
8abbdee71cf5 weather: Bump copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 365
diff changeset
4 # (C) Copyright 2014-2017 Tecnic Software productions (TNSP)
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #
183
4abb7a940e24 weather: Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
6 # Requires data fetcher to be run as a cronjob, see fetch_weather.pl
4abb7a940e24 weather: Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
7 # for more information.
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 # This script is freely distributable under GNU GPL (version 2) license.
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
273
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
13 ### The configuration should be in config.weather in same directory
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
14 ### as this script. Or change the line below to point where ever
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
15 ### you wish. See "config.weather.example" for an example config file.
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
16 source [file dirname [info script]]/config.weather
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
344
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
18 ### Required utillib.tcl
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
19 source [file dirname [info script]]/utillib.tcl
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
20
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 # No need to look below this line
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 ##########################################################################
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 set weather_name "Weather"
415
ff932030a9b3 weather: Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 414
diff changeset
26 set weather_version "0.9.5"
184
a496dc87a7c1 weather: Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 183
diff changeset
27
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 ### Initialization messages
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 package require textutil::split
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 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
32 putlog "$weather_message"
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 proc weather_log {arg} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 global weather_logmsg weather_name
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 if {$weather_logmsg != 0} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 putlog "$weather_name: $arg"
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
44 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
45 global weather_preferredmsg
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 if {$apublic == 1} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 putserv "$weather_preferredmsg $achan :$amsg"
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 } else {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 putserv "$weather_preferredmsg $anick :$amsg"
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
54 proc weather_msg {apublic anick achan amsg {aargs {}}} {
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
55 set narg 1
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
56 foreach marg $aargs {
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
57 set amsg [string map [list "%$narg" $marg] $amsg]
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
58 incr narg
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 weather_msg_do $apublic $anick $achan $amsg
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
61 }
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
62
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
63
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
64 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
65 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
66 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
67 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
68 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
69 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
70 } 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
71 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
72 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
73 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
74 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
75 incr nline
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
76 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
77 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
78
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
79
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
80 proc weather_valid_user {uhand} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
81 if {$uhand != "" && $uhand != "{}" && $uhand != "*"} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
82 return 1
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
83 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
84 return 0
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
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
87
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
88 #-------------------------------------------------------------------------
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
89 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
90 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
91
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
92 # Create dict
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
93 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
94 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
95
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
96 # Read datafile
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
97 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
98 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
99 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
100 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
101 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
102 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
103 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
104 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
105 close $ufile
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
106 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
107 weather_log "Could not open data file: $uerrmsg"
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
108 }
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
109 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
110
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 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
113 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
114
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
115 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
116 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
117 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
118 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
119 close $ufile
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
120 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
121 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
122 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
123 }
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
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
126 # 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
127 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
128 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
129 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
130 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
131 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
132 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
133 return $uname
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
134 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
135
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 #-------------------------------------------------------------------------
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
138 # Produce one location of weather data as a string
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
139 proc weather_get_str {udata umsg} {
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
140
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
141 array unset uvals
287
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
142 set uvals(station) [lindex $udata 0]
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
143 set uvals(type) [lindex $udata 1]
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
144 set uvals(c_lat) [lindex $udata 2]
419
3566fdca974b weather: Rename a string token.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
145 set uvals(c_lng) [lindex $udata 3]
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
146 set uvals(c_height) [lindex $udata 4]
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
147 set uvals(vtime) [lindex $udata 5]
360
2f7f18371b65 weather: Adjust time handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
148
2f7f18371b65 weather: Adjust time handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
149 if {[expr [clock seconds] - $uvals(vtime)] < 3600} {
357
b1e7ffeaacef weather: Adjust time output handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 345
diff changeset
150 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M"]
b1e7ffeaacef weather: Adjust time output handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 345
diff changeset
151 } else {
360
2f7f18371b65 weather: Adjust time handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 358
diff changeset
152 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M (%d.%m.%Y)"]
357
b1e7ffeaacef weather: Adjust time output handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 345
diff changeset
153 }
b1e7ffeaacef weather: Adjust time output handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 345
diff changeset
154
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
155 set uvals(temp) [lindex $udata 6]
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
156
238
a1d6e2d8789e Add new data from FMI service and change datafile format.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
157 if {[lindex $udata 1] == 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
158 set uvals(road_temp) [lindex $udata 7]
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
159 set uvals(weather1) [lindex $udata 8]
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
160 set uvals(weather2) [lindex $udata 9]
287
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
161 } else {
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
162 set uvals(humidity) [lindex $udata 7]
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
163 set uvals(wind_speed) [lindex $udata 8]
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
164 set uvals(cloud_cover) [lindex $udata 9]
287
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
165 }
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
166
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
167 set astr ""
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
168 foreach aitem $umsg {
287
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
169 set atmp $aitem
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
170 foreach {akey aval} [array get uvals] {
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
171 if {$aval != ""} {
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
172 set atmp [string map [list "@${akey}@" $aval] $atmp]
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
173 }
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
174 }
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
175 if {$atmp != $aitem || [string first "@" $aitem] < 0} {
287
748c6b44f572 weather: Fix translation routine.
Matti Hamalainen <ccr@tnsp.org>
parents: 286
diff changeset
176 append astr $atmp
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
177 }
238
a1d6e2d8789e Add new data from FMI service and change datafile format.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
178 }
285
259f093c9503 weather: Make some more messages configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
179
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
180 return $astr
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
181 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
182
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
183
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
184 # Get data by location key
279
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
185 proc weather_get_by_key {ukey} {
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
186 global weather_data weather_msg_result
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
187 return [weather_get_str $weather_data($ukey) $weather_msg_result]
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
188 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
189
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
190
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 proc weather_update {} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 global weather_datafile weather_data
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
172
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
195 # 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
196 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
197 # Create dict
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
198 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
199 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
200
172
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
201 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
202 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
203 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
204 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
205
2c89e47739e8 weather: Change weather data loading to not discard current data if data
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
206 # Read in the data
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 while {![eof $ufile]} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 gets $ufile uline
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 set udata [split $uline "|"]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 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
211 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
212 set ukey [lindex $udata 0]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 set weather_data($ukey) $udata
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
216 if {[string is double -strict $utemp]} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
217 if {$utemp < $wtemp_min_val} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
218 set wtemp_min_key $ukey
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
219 set wtemp_min_val $utemp
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
220 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
221 if {$utemp > $wtemp_max_val} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
222 set wtemp_max_key $ukey
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
223 set wtemp_max_val $utemp
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
224 }
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 close $ufile
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
334
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
230 # Store min/max
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
231 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
232 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
233 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
234 } else {
088bb2621595 weather: Do not attempt to access weather data through unset / invalid
Matti Hamalainen <ccr@tnsp.org>
parents: 287
diff changeset
235 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
236 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
237 }
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 } else {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 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
240 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 #-------------------------------------------------------------------------
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
245 # Weather data update loop
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 proc weather_exec {} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 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
248
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 # Perform update
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 weather_update
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 # Schedule next update
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 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
254 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
255 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 #-------------------------------------------------------------------------
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
259 # Script initialization
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
260 #-------------------------------------------------------------------------
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
261
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 if {![info exists weather_data]} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 array set weather_data {}
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
266 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
267 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
268 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
269
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 if {[info exists weather_running]} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 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
272 } else {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 set weather_last -1
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
276 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
277 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
278
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 if {$weather_last < 0 || $weather_last > [expr $weather_check_period * 60]} {
364
3b67c66fe0dc weather: Add debugging prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 360
diff changeset
280 weather_log "Starting weather update timer."
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 weather_exec
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 } else {
364
3b67c66fe0dc weather: Add debugging prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 360
diff changeset
283 weather_log "Continuing weather updates."
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 weather_update
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
287
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 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
290 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
291 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
292 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
293 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
294 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
295 global weather_msg_def_set weather_msg_def_not_set weather_msg_aliases
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
296 global weather_msg_usage_stations weather_msg_stations weather_msg_list_station
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
297 global weather_msg_result
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
298
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 # Check and handle arguments
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 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
301 set rarg [lindex $rarglist 0]
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 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
304 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
305 return 0
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 }
217
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 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
309 # 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
310 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
311 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
312 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
313 }
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
314
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
315 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
316 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
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 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
319 if {![string match "w_*" $ukey] && [string match -nocase "*${rarg}*" $ukey]} {
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
320 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
321 }
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
322 }
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
323
67018e353536 weather: Add new sub-command for listing measurement stations matching given name pattern.
Matti Hamalainen <ccr@tnsp.org>
parents: 215
diff changeset
324 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
325 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
326 return 0
273
38a5bce4b078 weather: Move configuration to separate file.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
327 } 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
328 # 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
329
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
330 # 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
331 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
332 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
333 return 0
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
334 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
335
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
336 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
337 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
338 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
339 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
340 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
341 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
342 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
343 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
344 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
345 # 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
346 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
347 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
348
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
349 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
350 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
351 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
352 } else {
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
353 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
354 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
355 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
356 return 0
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
357 } elseif {$rarg == "alias"} {
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
358 # 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
359 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
360 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
361 return 0
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
364 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
365 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
366 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
367 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
368 return 0
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
369 }
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
370
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
371 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
372 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
373 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
374 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
375
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
376 weather_save_aliases
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 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
378 } elseif {$rarg == "unalias"} {
171
5434903331df weather: Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 167
diff changeset
379 # 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
380 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
381 weather_msg $upublic $unick $uchan $weather_msg_no_access
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
382 return 0
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
383 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
384
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
385 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
386 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
387 return 0
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
388 }
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
389
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
390 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
391 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
392 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
393
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
394 weather_save_aliases
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
395 return 0
174
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
396 } elseif {$rarg == "list"} {
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
397 # List all currently defined aliases
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
398 set ulist {}
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
399 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
400 lappend ulist "\002'$ukey' = '$uvalue'\002"
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
401 }
d94be9a1be6a weather: Add support for listing currently defined aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 173
diff changeset
402 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
403 return 0
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
404 }
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
405
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 # 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
407 set rargs [join $rarglist " "]
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
408 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
409 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
410 }
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
411 if {$rargs == ""} {
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 set rargs $weather_default_locations
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 # Handle argument list
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
416 set nresults 0
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 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
418 foreach rarg $rarglist {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 if {$rarg == "min"} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 # Min temp
279
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
421 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
422 weather_msg $upublic $unick $uchan "Min: $umin"
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
423 incr nresults
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 } elseif {$rarg == "max"} {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 # Max temp
279
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 "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 } 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
430 # Min & Max temps
279
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
431 set umin [weather_get_by_key "w_min"]
f6dc673adfa1 weather: Reorder some function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 273
diff changeset
432 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
433 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
434 incr nresults
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 } else {
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 # Location match
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 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
438 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
439 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
440 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
441 if {[llength $uvalue] > 0} {
418
e904b453a06a weather: Show weather station coordinates and Google Maps link in the station list search.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
442 weather_msg $upublic $unick $uchan [weather_get_str $uvalue $weather_msg_result]
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
443 incr nresults
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 } else {
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
445 weather_msg $upublic $unick $uchan $weather_msg_no_results [list $ukey]
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 incr ufound
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
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 # Check for results limit
161
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
451 if {$nresults >= $weather_max_results} {
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
452 return 0
2c9db9a29429 weather: More work, bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
453 }
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 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
457 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
458 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 }
163
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
460
bee5cd89d41c weather: Moar work on getting the frontend script code up and running.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
461 # Check for results limit
156
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
462 if {$nresults >= $weather_max_results} {
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
463 return 0
a1f4c163e48c weather: Add max results limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
464 }
153
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 return 0
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 #-------------------------------------------------------------------------
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 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
473 global weather_channels
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
474
344
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
475 if {[utl_match_delim_list $weather_channels $uchan]} {
25fc5a2b42ae weather: Use utillib for matching enabled channels.
Matti Hamalainen <ccr@tnsp.org>
parents: 335
diff changeset
476 return [weather_cmd $unick $uhand $uchan $uargs 1]
220
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
477 }
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
478
03579553233b weather: Add setting for specifying channels where weather commands are available.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
479 return 0
153
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 }
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 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
484 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
485 }
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486
8b888a9f07df New script, weather.tcl. Needs backend stuff to be implemented.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 # end of script