- local cmd = string.format(current_call, city_id, units, lang)
- async.request(cmd, function(f)
- j = f:read("*a")
- f:close()
- weather_now, pos, err = json.decode(j, 1, nil)
-
- if not err and weather_now ~= nil and tonumber(weather_now["cod"]) == 200 then
- weather.icon_path = icons_path .. weather_now["weather"][1]["icon"] .. ".png"
- weather.icon:set_image(weather.icon_path)
+ local cmd = string.format(current_call, city_id, units, lang, APPID)
+ helpers.async(cmd, function(f)
+ local pos, err, icon
+ weather_now, pos, err = json.decode(f, 1, nil)
+
+ if not err and type(weather_now) == "table" and tonumber(weather_now["cod"]) == 200 then
+ -- weather icon based on localtime
+ local now = os.time()
+ local sunrise = tonumber(weather_now["sys"]["sunrise"])
+ local sunset = tonumber(weather_now["sys"]["sunset"])
+ 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
+
+ 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
+ now = now - 86400
+ elseif offset < 0 and loc_m <= utc_m then
+ now = now + 86400
+ end
+
+ if sunrise <= now and now <= sunset then
+ icon = string.gsub(icon, "n", "d")
+ else
+ icon = string.gsub(icon, "d", "n")
+ end
+
+ weather.icon_path = icons_path .. icon .. ".png"