mirror of https://github.com/lcpz/lain.git
Openweathermap license conditions and API changes
This commit is contained in:
parent
beaa7abac2
commit
01d4f14919
|
@ -27,7 +27,7 @@ local function factory(args)
|
||||||
local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain's default
|
local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain's default
|
||||||
local timeout = args.timeout or 60 * 15 -- 15 min
|
local timeout = args.timeout or 60 * 15 -- 15 min
|
||||||
local current_call = args.current_call or "curl -s 'https://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'"
|
local current_call = args.current_call or "curl -s 'https://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'"
|
||||||
local forecast_call = args.forecast_call or "curl -s 'https://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'"
|
local forecast_call = args.forecast_call or "curl -s 'https://api.openweathermap.org/data/2.5/forecast?id=%s&units=%s&lang=%s&APPID=%s'"
|
||||||
local city_id = args.city_id or 0 -- placeholder
|
local city_id = args.city_id or 0 -- placeholder
|
||||||
local units = args.units or "metric"
|
local units = args.units or "metric"
|
||||||
local lang = args.lang or "en"
|
local lang = args.lang or "en"
|
||||||
|
@ -37,8 +37,8 @@ local function factory(args)
|
||||||
local notification_text_fun = args.notification_text_fun or
|
local notification_text_fun = args.notification_text_fun or
|
||||||
function (wn)
|
function (wn)
|
||||||
local day = os.date("%a %d", wn["dt"])
|
local day = os.date("%a %d", wn["dt"])
|
||||||
local tmin = math.floor(wn["temp"]["min"])
|
local tmin = math.floor(wn["main"]["temp_min"])
|
||||||
local tmax = math.floor(wn["temp"]["max"])
|
local tmax = math.floor(wn["main"]["temp_max"])
|
||||||
local desc = wn["weather"][1]["description"]
|
local desc = wn["weather"][1]["description"]
|
||||||
return string.format("<b>%s</b>: %s, %d - %d ", day, desc, tmin, tmax)
|
return string.format("<b>%s</b>: %s, %d - %d ", day, desc, tmin, tmax)
|
||||||
end
|
end
|
||||||
|
@ -88,14 +88,14 @@ local function factory(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function weather.forecast_update()
|
function weather.forecast_update()
|
||||||
local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID)
|
local cmd = string.format(forecast_call, city_id, units, lang, APPID)
|
||||||
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)
|
||||||
|
|
||||||
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"] do
|
for i = 1, weather_now["cnt"], 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
|
||||||
|
|
Loading…
Reference in New Issue