comparison weather.tcl @ 690:8a6cca58e853

fetch_weather, weather: Update to match with Digitraffic API changes.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 22 Jun 2023 13:32:07 +0300
parents 2723be85343a
children e1aba44b8c7b
comparison
equal deleted inserted replaced
689:299a17b98f84 690:8a6cca58e853
1 ########################################################################## 1 ##########################################################################
2 # 2 #
3 # Weather v2.1.0 by Matti 'ccr' Hamalainen <ccr@tnsp.org> 3 # Weather v2.2.0 by Matti 'ccr' Hamalainen <ccr@tnsp.org>
4 # (C) Copyright 2014-2021 Tecnic Software productions (TNSP) 4 # (C) Copyright 2014-2023 Tecnic Software productions (TNSP)
5 # 5 #
6 # Requires data fetcher to be run as a cronjob, see fetch_weather.pl 6 # Requires data fetcher to be run as a cronjob, see fetch_weather.pl
7 # for more information. 7 # for more information.
8 # 8 #
9 # This script is freely distributable under GNU GPL (version 2) license. 9 # This script is freely distributable under GNU GPL (version 2) license.
23 # No need to look below this line 23 # No need to look below this line
24 ########################################################################## 24 ##########################################################################
25 package require textutil::split 25 package require textutil::split
26 26
27 set weather_name "Weather" 27 set weather_name "Weather"
28 set weather_message "$weather_name v2.1.0 (C) 2014-2021 ccr/TNSP" 28 set weather_message "$weather_name v2.2.0 (C) 2014-2023 ccr/TNSP"
29 29
30 30
31 #------------------------------------------------------------------------- 31 #-------------------------------------------------------------------------
32 ### Utility functions 32 ### Utility functions
33 proc weather_log {umsg} { 33 proc weather_log {umsg} {
128 # Read in the data 128 # Read in the data
129 while {![eof $ufile]} { 129 while {![eof $ufile]} {
130 gets $ufile uline 130 gets $ufile uline
131 set udata [split $uline "|"] 131 set udata [split $uline "|"]
132 if {[llength $udata] > 0} { 132 if {[llength $udata] > 0} {
133 set utemp [lindex $udata 6] 133 set utemp [lindex $udata 4]
134 set ukey [lindex $udata 0] 134 set ukey [lindex $udata 0]
135 135
136 set weather_data($ukey) $udata 136 set weather_data($ukey) $udata
137 137
138 if {[string is double -strict $utemp]} { 138 if {[string is double -strict $utemp]} {
229 global weather_msg_cloudiness 229 global weather_msg_cloudiness
230 global weather_msg_precipitation 230 global weather_msg_precipitation
231 231
232 array unset uvals 232 array unset uvals
233 set uvals(station) [lindex $udata 0] 233 set uvals(station) [lindex $udata 0]
234 set uvals(type) [lindex $udata 1] 234 set uvals(c_lat) [lindex $udata 1]
235 set uvals(c_lat) [lindex $udata 2] 235 set uvals(c_lng) [lindex $udata 2]
236 set uvals(c_lng) [lindex $udata 3] 236 set uvals(vtime) [lindex $udata 3]
237 set uvals(c_height) [lindex $udata 4] 237 set uvals(temp) [lindex $udata 4]
238 set uvals(vtime) [lindex $udata 5] 238 set uvals(humidity) [lindex $udata 5]
239 set uvals(temp) [lindex $udata 6] 239 set uvals(wind_speed) [lindex $udata 6]
240 set uvals(humidity) [lindex $udata 7] 240 set uvals(wind_direction) [weather_get_wind_direction [lindex $udata 7]]
241 set uvals(wind_speed) [lindex $udata 8] 241 set uvals(wind_direction_deg) [lindex $udata 7]
242 set uvals(wind_direction) [weather_get_wind_direction [lindex $udata 9]] 242 set uvals(cloudiness) [weather_get_table_value $weather_msg_cloudiness [lindex $udata 8]]
243 set uvals(wind_direction_deg) [lindex $udata 9] 243 set uvals(cloudiness_val) [weather_get_raw_table_value $weather_msg_cloudiness [lindex $udata 8]]
244 set uvals(cloudiness) [weather_get_table_value $weather_msg_cloudiness [lindex $udata 10]] 244 set uvals(road_surface_temp) [lindex $udata 9]
245 set uvals(cloudiness_val) [weather_get_raw_table_value $weather_msg_cloudiness [lindex $udata 10]] 245 set uvals(precipitation) [lindex $udata 10]
246 set uvals(road_surface_temp) [lindex $udata 11] 246 set uvals(visibility) [lindex $udata 11]
247 set uvals(precipitation) [lindex $udata 12] 247 set uvals(precipitation2) [weather_get_table_value $weather_msg_precipitation [lindex $udata 12]]
248 set uvals(visibility) [lindex $udata 13] 248 set uvals(precipitation_val) [weather_get_raw_table_value $weather_msg_precipitation [lindex $udata 13]]
249 set uvals(precipitation2) [weather_get_table_value $weather_msg_precipitation [lindex $udata 14]]
250 set uvals(precipitation_val) [weather_get_raw_table_value $weather_msg_precipitation [lindex $udata 14]]
251 249
252 if {[expr [clock seconds] - $uvals(vtime)] < 3600} { 250 if {[expr [clock seconds] - $uvals(vtime)] < 3600} {
253 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M"] 251 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M"]
254 } else { 252 } else {
255 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M (%d.%m.%Y)"] 253 set uvals(ctime) [clock format $uvals(vtime) -format "%H:%M (%d.%m.%Y)"]