WIP
This commit is contained in:
parent
088612e670
commit
ecbb409cd7
1 changed files with 25 additions and 20 deletions
|
@ -109,38 +109,43 @@ 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.
|
|
||||||
|
--[[ 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)
|
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
|
helpers.async(sun_position_cmd, function(g)
|
||||||
local sunrise = tonumber(sun_position["daily"]["data"][1]["sunriseTime"])
|
sun_position, _, err = json.decode(g, 1, nil)
|
||||||
local sunset = tonumber(weather_now["daily"]["data"][1]["sunsetTime"])
|
|
||||||
local icon = weather_now["daily"]["icon"]
|
|
||||||
local loc_now = os.time()
|
|
||||||
|
|
||||||
if sunrise <= loc_now and loc_now <= sunset then
|
if not err and type(sun_position) == "table" and type(weather_now) == "table" then
|
||||||
icon = string.gsub(icon, "n", "d")
|
local sunrise = tonumber(sun_position["daily"]["data"][1]["sunriseTime"])
|
||||||
|
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
|
||||||
|
icon = string.gsub(icon, "n", "d")
|
||||||
|
else
|
||||||
|
icon = string.gsub(icon, "d", "n")
|
||||||
|
end
|
||||||
|
|
||||||
|
weather.icon_path = icons_path .. icon .. ".png"
|
||||||
|
widget = weather.widget
|
||||||
|
settings()
|
||||||
else
|
else
|
||||||
icon = string.gsub(icon, "d", "n")
|
weather.icon_path = icons_path .. "na.png"
|
||||||
|
weather.widget:set_markup(weather_na_markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
weather.icon_path = icons_path .. icon .. ".png"
|
weather.icon:set_image(weather.icon_path)
|
||||||
widget = weather.widget
|
end)
|
||||||
settings()
|
|
||||||
else
|
|
||||||
weather.icon_path = icons_path .. "na.png"
|
|
||||||
weather.widget:set_markup(weather_na_markup)
|
|
||||||
end
|
|
||||||
|
|
||||||
weather.icon:set_image(weather.icon_path)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue