From afd51e20bb19881c149cced856f7573fc64ec50d Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Fri, 27 May 2016 13:01:58 +1200 Subject: [PATCH 01/10] modified: widgets/weather.lua - fixed the OWM "feature" for icon day/night state calculated in accordance with current GMT time (it seems OWM knows nothing of local time and time zones) --- widgets/weather.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index ca0ceed..f60a8fc 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -117,11 +117,20 @@ local function worker(args) function weather.update() local cmd = string.format(current_call, city_id, units, lang, APPID) async.request(cmd, function(f) - local pos, err + local pos, err, sunrise, sunset, current_dt, datetime, icon weather_now, pos, err = json.decode(f, 1, nil) if not err and weather_now and tonumber(weather_now["cod"]) == 200 then - weather.icon_path = icons_path .. weather_now["weather"][1]["icon"] .. ".png" + current_dt = os.time() + sunrise = weather_now["sys"]["sunrise"] + sunset = weather_now["sys"]["sunset"] + if current_dt > sunrise and current_dt < sunset then + datetime="d" + else + datetime="n" + end + icon = weather_now["weather"][1]["icon"] + weather.icon_path = icons_path .. icon:sub(1,2) .. datetime .. ".png" widget = weather.widget settings() else From e6e0889fb21590b11fdfebef80029efa2bec84eb Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Fri, 27 May 2016 14:52:18 +1200 Subject: [PATCH 02/10] modified: widgets/weather.lua - added current weather description to notification --- widgets/weather.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index f60a8fc..cd8f6ab 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -70,8 +70,12 @@ local function worker(args) weather.forecast_update() end + if not weather.current_text then + weather.update() + end + weather.notification = naughty.notify({ - text = weather.notification_text, + text = weather.current_text .. weather.notification_text, icon = weather.icon_path, timeout = t_out, preset = notification_preset @@ -119,7 +123,7 @@ local function worker(args) async.request(cmd, function(f) local pos, err, sunrise, sunset, current_dt, datetime, icon weather_now, pos, err = json.decode(f, 1, nil) - + weather.current_text='' if not err and weather_now and tonumber(weather_now["cod"]) == 200 then current_dt = os.time() sunrise = weather_now["sys"]["sunrise"] @@ -132,6 +136,7 @@ local function worker(args) icon = weather_now["weather"][1]["icon"] weather.icon_path = icons_path .. icon:sub(1,2) .. datetime .. ".png" widget = weather.widget + weather.current_text = "Now:" .. weather_now["weather"][1]["description"] .. "\n" settings() else weather.icon_path = icons_path .. "na.png" From e3a5dd623700b2cad423c8179141124e6e9b9027 Mon Sep 17 00:00:00 2001 From: Trap000d Date: Sun, 29 May 2016 11:15:07 +1200 Subject: [PATCH 03/10] modified: widgets/weather.lua - fixed +- 1 day difference due to UTC time --- widgets/weather.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/widgets/weather.lua b/widgets/weather.lua index cd8f6ab..df34040 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -128,11 +128,13 @@ local function worker(args) current_dt = os.time() sunrise = weather_now["sys"]["sunrise"] sunset = weather_now["sys"]["sunset"] + if current_dt> sunrise and current_dt> sunset then current_dt = current_dt - 86400 end if current_dt > sunrise and current_dt < sunset then datetime="d" else datetime="n" end + -- error("dt sr:" .. sunrise .. "ss: " .. sunset .. "dt: " .. current_dt .. "d/n: " .. datetime .. "hehe") icon = weather_now["weather"][1]["icon"] weather.icon_path = icons_path .. icon:sub(1,2) .. datetime .. ".png" widget = weather.widget From 321274e33237aefa896eabcf6fb0b2c439cd2bdb Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Mon, 30 May 2016 12:50:42 +1200 Subject: [PATCH 04/10] modified: widgets/weather.lua - test if the tomorrow came --- widgets/weather.lua | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index c684fe2..3512f22 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -73,8 +73,9 @@ local function worker(args) weather.forecast_update() end + weather.notification = naughty.notify({ - text = weather.current_text .. weather.notification_text, + text = weather.notification_text, icon = weather.icon_path, timeout = t_out, preset = notification_preset @@ -122,39 +123,25 @@ local function worker(args) async.request(cmd, function(f) local pos, err, icon weather_now, pos, err = json.decode(f, 1, nil) - weather.current_text='' + if not err and weather_now and tonumber(weather_now["cod"]) == 200 then -<<<<<<< HEAD -- weather icon based on localtime - now = os.time() - (utc * 3600) + now = os.time() sunrise = tonumber(weather_now["sys"]["sunrise"]) sunset = tonumber(weather_now["sys"]["sunset"]) icon = weather_now["weather"][1]["icon"] + if sunrise <= (now-86400) then now = now - 86400 end + if sunrise <= now and now <= sunset then icon = string.gsub(icon, "n", "d") -======= - current_dt = os.time() - sunrise = weather_now["sys"]["sunrise"] - sunset = weather_now["sys"]["sunset"] - if current_dt> sunrise and current_dt> sunset then current_dt = current_dt - 86400 end - if current_dt > sunrise and current_dt < sunset then - datetime="d" ->>>>>>> e3a5dd623700b2cad423c8179141124e6e9b9027 else icon = string.gsub(icon, "d", "n") end -<<<<<<< HEAD weather.icon_path = icons_path .. icon .. ".png" -======= - -- error("dt sr:" .. sunrise .. "ss: " .. sunset .. "dt: " .. current_dt .. "d/n: " .. datetime .. "hehe") - icon = weather_now["weather"][1]["icon"] - weather.icon_path = icons_path .. icon:sub(1,2) .. datetime .. ".png" ->>>>>>> e3a5dd623700b2cad423c8179141124e6e9b9027 widget = weather.widget - weather.current_text = "Now:" .. weather_now["weather"][1]["description"] .. "\n" settings() else weather.icon_path = icons_path .. "na.png" From 40d3c9e33af88711c78b50b5eb3d2d48388f796e Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Tue, 31 May 2016 14:05:44 +1200 Subject: [PATCH 05/10] modified: widgets/weather.lua - seems fixed datetime calculation --- widgets/weather.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index 3512f22..84c1564 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -39,6 +39,7 @@ local function worker(args) local forecast_call = args.forecast_call or "curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'" local city_id = args.city_id or 0 -- placeholder local utc = args.utc or 0 + local units = args.units or "metric" local lang = args.lang or "en" local cnt = args.cnt or 5 @@ -120,19 +121,31 @@ local function worker(args) function weather.update() local cmd = string.format(current_call, city_id, units, lang, APPID) + local utc_midnight_cmd = ("date -u -d 'today 00:00:00' +'%%s'") + async.request(cmd, function(f) local pos, err, icon weather_now, pos, err = json.decode(f, 1, nil) if not err and weather_now and tonumber(weather_now["cod"]) == 200 then -- weather icon based on localtime + now = os.time() + utc_midnight = string.gsub(read_pipe(string.format(utc_midnight_cmd)), "\n", "") + + if utc > 0 then + if (now - (utc * 3600)) >= tonumber(utc_midnight) then + now = now - 86400 + end + else + if (now - (utc * 3600)) <= tonumber(utc_midnight) then + now = now + 86400 + end + end sunrise = tonumber(weather_now["sys"]["sunrise"]) sunset = tonumber(weather_now["sys"]["sunset"]) icon = weather_now["weather"][1]["icon"] - if sunrise <= (now-86400) then now = now - 86400 end - if sunrise <= now and now <= sunset then icon = string.gsub(icon, "n", "d") else From 0493baffd5f17b6331974ae1dac4d404d016e351 Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Wed, 1 Jun 2016 11:19:39 +1200 Subject: [PATCH 06/10] another attempt to fix weather widget behaviour --- widgets/weather.lua | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index 84c1564..042d1e7 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -21,7 +21,7 @@ local mouse = mouse local os = { time = os.time } local string = { format = string.format, gsub = string.gsub } - +local naughty = require("naughty") local tonumber = tonumber local setmetatable = setmetatable @@ -39,7 +39,6 @@ local function worker(args) local forecast_call = args.forecast_call or "curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'" local city_id = args.city_id or 0 -- placeholder local utc = args.utc or 0 - local units = args.units or "metric" local lang = args.lang or "en" local cnt = args.cnt or 5 @@ -121,7 +120,8 @@ local function worker(args) function weather.update() local cmd = string.format(current_call, city_id, units, lang, APPID) - local utc_midnight_cmd = ("date -u -d 'today 00:00:00' +'%%s'") + local utc_midnight_cmd = string.format("date -u -d 'today 00:00:00' +'%%s'") + local local_midnight_cmd = string.format("date -d 'today 00:00:00' +'%%s'") async.request(cmd, function(f) local pos, err, icon @@ -129,22 +129,25 @@ local function worker(args) if not err and weather_now and tonumber(weather_now["cod"]) == 200 then -- weather icon based on localtime - - now = os.time() - utc_midnight = string.gsub(read_pipe(string.format(utc_midnight_cmd)), "\n", "") - - if utc > 0 then - if (now - (utc * 3600)) >= tonumber(utc_midnight) then + now = os.time() + local utc_midnight = string.gsub(read_pipe(utc_midnight_cmd), "\n", "") + local local_midnight = string.gsub(read_pipe(local_midnight_cmd), "\n", "") + + if utc > 0 then -- we are to the East from GMT + if tonumber(local_midnight) >= tonumber(utc_midnight) then -- we are 1 day after the GMT, so have to return 1 day back now = now - 86400 end - else - if (now - (utc * 3600)) <= tonumber(utc_midnight) then + end + + if utc < 0 then -- we are to the West from GMT + if tonumber(local_midnight) <= tonumber(utc_midnight) then -- we are 1 day before the GMT now = now + 86400 end end - sunrise = tonumber(weather_now["sys"]["sunrise"]) - sunset = tonumber(weather_now["sys"]["sunset"]) - icon = weather_now["weather"][1]["icon"] + -- if utc==0 leave it as is + local sunrise = tonumber(weather_now["sys"]["sunrise"]) + local sunset = tonumber(weather_now["sys"]["sunset"]) + local icon = weather_now["weather"][1]["icon"] if sunrise <= now and now <= sunset then icon = string.gsub(icon, "n", "d") From 701352911743921833d901bd6fa2728be148cceb Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Thu, 2 Jun 2016 19:44:19 +1200 Subject: [PATCH 07/10] Fix boolean with number comparison --- widgets/weather.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index b074cff..d2ed300 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -43,7 +43,7 @@ local function worker(args) local utc_offset = args.utc_offset or function () local now = os.time() - return os.difftime(now, os.time(os.date("!*t", now))) + (os.date("*t").isdst and 3600) + return os.difftime(now, os.time(os.date("!*t", now))) + ((os.date("*t").isdst and 1 or 0) * 3600) end local units = args.units or "metric" local lang = args.lang or "en" From c754dde180c2b18cdfb538dbf715abb20af20e21 Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Mon, 6 Feb 2017 14:40:19 +1300 Subject: [PATCH 08/10] Fix for local vs utc time offset --- widgets/weather.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index 1e398cc..9e1b80e 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -130,7 +130,13 @@ local function worker(args) local icon = weather_now["weather"][1]["icon"] local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 } local offset = utc_offset() - local utc_m = loc_m + offset + local utc_m = loc_m - offset + + if offset > 0 and (now - utc_m)>=86400 then + utc_m = utc_m + 86400 + elseif offset < 0 and (utc_m - now)>=86400 then + utc_m = utc_m - 86400 + end -- if we are 1 day after the GMT, return 1 day back, and viceversa if offset > 0 and loc_m >= utc_m then From a0da152bb39c5c3ae239a5743c40cb35038c4a21 Mon Sep 17 00:00:00 2001 From: Aleksandr Beliaev Date: Mon, 6 Feb 2017 14:40:19 +1300 Subject: [PATCH 09/10] Fix for local vs utc time offset --- widgets/weather.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/widgets/weather.lua b/widgets/weather.lua index 1e398cc..9e1b80e 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -130,7 +130,13 @@ local function worker(args) local icon = weather_now["weather"][1]["icon"] local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 } local offset = utc_offset() - local utc_m = loc_m + offset + local utc_m = loc_m - offset + + if offset > 0 and (now - utc_m)>=86400 then + utc_m = utc_m + 86400 + elseif offset < 0 and (utc_m - now)>=86400 then + utc_m = utc_m - 86400 + end -- if we are 1 day after the GMT, return 1 day back, and viceversa if offset > 0 and loc_m >= utc_m then