From: Aleksandr Beliaev Date: Fri, 27 May 2016 01:01:58 +0000 (+1200) Subject: modified: widgets/weather.lua - fixed the OWM "feature" for icon day/night state... X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/afd51e20bb19881c149cced856f7573fc64ec50d?hp=-c 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) --- afd51e20bb19881c149cced856f7573fc64ec50d 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