WIP
This commit is contained in:
parent
088612e670
commit
ecbb409cd7
1 changed files with 25 additions and 20 deletions
|
@ -109,21 +109,25 @@ local function factory(args)
|
|||
end)
|
||||
end
|
||||
|
||||
function weather.is_daytime() end
|
||||
|
||||
function weather.update()
|
||||
local cmd = string.format(current_call, APPID, lat, lon, units)
|
||||
|
||||
helpers.async(cmd, function(f)
|
||||
local err
|
||||
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 sunset = tonumber(weather_now["daily"]["data"][1]["sunsetTime"])
|
||||
local icon = weather_now["daily"]["icon"]
|
||||
local sunset = tonumber(sun_position["daily"]["data"][1]["sunsetTime"])
|
||||
local icon = sun_position["daily"]["icon"]
|
||||
local loc_now = os.time()
|
||||
|
||||
if sunrise <= loc_now and loc_now <= sunset then
|
||||
|
@ -142,6 +146,7 @@ local function factory(args)
|
|||
|
||||
weather.icon:set_image(weather.icon_path)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
if showpopup == "on" then
|
||||
|
|
Loading…
Add table
Reference in a new issue