Testing again
Some checks failed
Lain / linting (push) Has been cancelled
Lain / rockspec (push) Has been cancelled

This commit is contained in:
Adam Cooper 2025-02-28 04:23:16 -05:00
parent d96b3a1258
commit 6ea7b44fbb

View file

@ -16,7 +16,7 @@ local string = string
local type = type local type = type
local tonumber = tonumber local tonumber = tonumber
-- OpenWeatherMap -- OpenWeatherMap -- TODO: Change to PirateWeather
-- current weather and X-days forecast -- current weather and X-days forecast
-- lina.widget.weather -- lina.widget.weather
@ -26,8 +26,10 @@ local function factory(args)
local weather = { widget = args.widget or wibox.widget.textbox() } local weather = { widget = args.widget or wibox.widget.textbox() }
local APPID = args.APPID -- mandatory api key local APPID = args.APPID -- mandatory api key
local timeout = args.timeout or 900 -- 15 min local timeout = args.timeout or 900 -- 15 min
local current_call = args.current_call or "curl -s 'https://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&APPID=%s&units=%s&lang=%s'" local current_call = args.current_call
local forecast_call = args.forecast_call or "curl -s 'https://api.openweathermap.org/data/2.5/forecast?lat=%s&lon=%s&APPID=%s&cnt=%s&units=%s&lang=%s'" or "curl -s 'https://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&APPID=%s&units=%s&lang=%s'"
local forecast_call = args.forecast_call
or "curl -s 'https://api.openweathermap.org/data/2.5/forecast?lat=%s&lon=%s&APPID=%s&cnt=%s&units=%s&lang=%s'"
local lat = args.lat or 0 -- placeholder local lat = args.lat or 0 -- placeholder
local lon = args.lon or 0 -- placeholder local lon = args.lon or 0 -- placeholder
local units = args.units or "metric" local units = args.units or "metric"
@ -35,8 +37,8 @@ local function factory(args)
local cnt = args.cnt or 5 local cnt = args.cnt or 5
local icons_path = args.icons_path or helpers.icons_dir .. "openweathermap/" local icons_path = args.icons_path or helpers.icons_dir .. "openweathermap/"
local notification_preset = args.notification_preset or {} local notification_preset = args.notification_preset or {}
local notification_text_fun = args.notification_text_fun or local notification_text_fun = args.notification_text_fun
function (wn) or function(wn)
local day = os.date("%a %d", wn["dt"]) local day = os.date("%a %d", wn["dt"])
local temp = math.floor(wn["main"]["temp"]) local temp = math.floor(wn["main"]["temp"])
local desc = wn["weather"][1]["description"] local desc = wn["weather"][1]["description"]
@ -63,12 +65,12 @@ local function factory(args)
weather.forecast_update() weather.forecast_update()
end end
weather.notification = naughty.notify { weather.notification = naughty.notify({
preset = notification_preset, preset = notification_preset,
text = weather.notification_text, text = weather.notification_text,
icon = weather.icon_path, icon = weather.icon_path,
timeout = type(seconds) == "number" and seconds or notification_preset.timeout timeout = type(seconds) == "number" and seconds or notification_preset.timeout,
} })
end end
function weather.hide() function weather.hide()
@ -97,8 +99,8 @@ local function factory(args)
if not err and type(weather_now) == "table" and tonumber(weather_now["cod"]) == 200 then if not err and type(weather_now) == "table" and tonumber(weather_now["cod"]) == 200 then
weather.notification_text = "" weather.notification_text = ""
for i = 1, weather_now["cnt"], math.floor(weather_now["cnt"] / cnt) do for i = 1, weather_now["cnt"], math.floor(weather_now["cnt"] / cnt) do
weather.notification_text = weather.notification_text .. weather.notification_text = weather.notification_text
notification_text_fun(weather_now["list"][i]) .. notification_text_fun(weather_now["list"][i])
if i < weather_now["cnt"] then if i < weather_now["cnt"] then
weather.notification_text = weather.notification_text .. "\n" weather.notification_text = weather.notification_text .. "\n"
end end
@ -138,10 +140,13 @@ local function factory(args)
end) end)
end end
if showpopup == "on" then weather.attach(weather.widget) end if showpopup == "on" then
weather.attach(weather.widget)
end
weather.timer = helpers.newtimer("weather-" .. lat .. ":" .. lon, timeout, weather.update, false, true) weather.timer = helpers.newtimer("weather-" .. lat .. ":" .. lon, timeout, weather.update, false, true)
weather.timer_forecast = helpers.newtimer("weather_forecast-" .. lat .. ":" .. lon, timeout, weather.forecast_update, false, true) weather.timer_forecast =
helpers.newtimer("weather_forecast-" .. lat .. ":" .. lon, timeout, weather.forecast_update, false, true)
return weather return weather
end end