Testing again
This commit is contained in:
parent
d96b3a1258
commit
6ea7b44fbb
1 changed files with 118 additions and 113 deletions
|
@ -16,7 +16,7 @@ local string = string
|
|||
local type = type
|
||||
local tonumber = tonumber
|
||||
|
||||
-- OpenWeatherMap
|
||||
-- OpenWeatherMap -- TODO: Change to PirateWeather
|
||||
-- current weather and X-days forecast
|
||||
-- lina.widget.weather
|
||||
|
||||
|
@ -26,8 +26,10 @@ local function factory(args)
|
|||
local weather = { widget = args.widget or wibox.widget.textbox() }
|
||||
local APPID = args.APPID -- mandatory api key
|
||||
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 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 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 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 lon = args.lon or 0 -- placeholder
|
||||
local units = args.units or "metric"
|
||||
|
@ -35,8 +37,8 @@ local function factory(args)
|
|||
local cnt = args.cnt or 5
|
||||
local icons_path = args.icons_path or helpers.icons_dir .. "openweathermap/"
|
||||
local notification_preset = args.notification_preset or {}
|
||||
local notification_text_fun = args.notification_text_fun or
|
||||
function (wn)
|
||||
local notification_text_fun = args.notification_text_fun
|
||||
or function(wn)
|
||||
local day = os.date("%a %d", wn["dt"])
|
||||
local temp = math.floor(wn["main"]["temp"])
|
||||
local desc = wn["weather"][1]["description"]
|
||||
|
@ -63,12 +65,12 @@ local function factory(args)
|
|||
weather.forecast_update()
|
||||
end
|
||||
|
||||
weather.notification = naughty.notify {
|
||||
weather.notification = naughty.notify({
|
||||
preset = notification_preset,
|
||||
text = weather.notification_text,
|
||||
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
|
||||
|
||||
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
|
||||
weather.notification_text = ""
|
||||
for i = 1, weather_now["cnt"], math.floor(weather_now["cnt"] / cnt) do
|
||||
weather.notification_text = weather.notification_text ..
|
||||
notification_text_fun(weather_now["list"][i])
|
||||
weather.notification_text = weather.notification_text
|
||||
.. notification_text_fun(weather_now["list"][i])
|
||||
if i < weather_now["cnt"] then
|
||||
weather.notification_text = weather.notification_text .. "\n"
|
||||
end
|
||||
|
@ -138,10 +140,13 @@ local function factory(args)
|
|||
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_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
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue