This commit is contained in:
Adam Cooper 2025-03-08 10:07:00 -05:00
parent 088612e670
commit ecbb409cd7

View file

@ -109,21 +109,25 @@ local function factory(args)
end) end)
end end
function weather.is_daytime() end
function weather.update() function weather.update()
local cmd = string.format(current_call, APPID, lat, lon, units) local cmd = string.format(current_call, APPID, lat, lon, units)
helpers.async(cmd, function(f) helpers.async(cmd, function(f)
local err local err
weather_now, _, err = json.decode(f, 1, nil) weather_now, _, err = json.decode(f, 1, nil)
--[[ TODO: Try nesting async calls; otherwise write a new function for the forecast call.
local sun_position_cmd = string.format(forecast_call, APPID, lat, lon, units)
sun_position, _, err = json.decode(sun_position_cmd, 1, nil)
--]]
if not err and type(weather_now) == "table" then --[[ TODO: Try nesting async calls; otherwise write a new function for the forecast call.--]]
local sun_position_cmd = string.format(forecast_call, APPID, lat, lon, units)
helpers.async(sun_position_cmd, function(g)
sun_position, _, err = json.decode(g, 1, nil)
if not err and type(sun_position) == "table" and type(weather_now) == "table" then
local sunrise = tonumber(sun_position["daily"]["data"][1]["sunriseTime"]) local sunrise = tonumber(sun_position["daily"]["data"][1]["sunriseTime"])
local sunset = tonumber(weather_now["daily"]["data"][1]["sunsetTime"]) local sunset = tonumber(sun_position["daily"]["data"][1]["sunsetTime"])
local icon = weather_now["daily"]["icon"] local icon = sun_position["daily"]["icon"]
local loc_now = os.time() local loc_now = os.time()
if sunrise <= loc_now and loc_now <= sunset then if sunrise <= loc_now and loc_now <= sunset then
@ -142,6 +146,7 @@ local function factory(args)
weather.icon:set_image(weather.icon_path) weather.icon:set_image(weather.icon_path)
end) end)
end)
end end
if showpopup == "on" then if showpopup == "on" then