local function Test_Task() local key = "SQfjxV9fAdBJq9jDr" local location = "beijing" local language = "zh-Hans" local unit = "c" local start = "0" local days = "5" local url = string.format("https://api.seniverse.com/v3/weather/daily.json?key=%s&location=%s&language=%s&unit=%s&start=%s&days=%s", key, location, language, unit, start, days) whiletruedo http.request("GET", url, nil, nil, nil, nil, cbFnc) sys.wait(30000) end end
local function cbFnc(result, prompt, head, body) log.info("cbFnc", result, prompt) if result and body then log.info("cbFnc", "bodyLen=" .. body:len()) local tjsondata, result, errinfo = json.decode(body) if result andtype(tjsondata)== "table" then local results = tjsondata["results"][1] local name = results["location"]["name"] log.info("name:", name) local daily1 = results["daily"][1] log.info("date:", daily1["date"]) log.info("text_day:", daily1["text_day"]) log.info("text_night:", daily1["text_night"]) local daily2 = results["daily"][2] log.info("date:", daily2["date"]) log.info("text_day:", daily2["text_day"]) log.info("text_night:", daily2["text_night"]) local daily3 = results["daily"][3] log.info("date:", daily3["date"]) log.info("text_day:", daily3["text_day"]) log.info("text_night:", daily3["text_night"]) log.info("last_update:", results["last_update"]) else log.info("testJson.decode error", errinfo) end end end
local function cbFnc(result, prompt, head, body) log.info("cbFnc", result, prompt) if result and body then log.info("cbFnc", "bodyLen=" .. body:len()) local tjsondata, result, errinfo = json.decode(body) if result and type(tjsondata) == "table" then local results = tjsondata["results"][1] local name = results["location"]["name"] log.info("name:", name) local daily1 = results["daily"][1] log.info("date:", daily1["date"]) log.info("text_day:", daily1["text_day"]) log.info("text_night:", daily1["text_night"]) local daily2 = results["daily"][2] log.info("date:", daily2["date"]) log.info("text_day:", daily2["text_day"]) log.info("text_night:", daily2["text_night"]) local daily3 = results["daily"][3] log.info("date:", daily3["date"]) log.info("text_day:", daily3["text_day"]) log.info("text_night:", daily3["text_night"]) log.info("last_update:", results["last_update"]) else log.info("testJson.decode error", errinfo) end end end
local function Test_Task()
local key = "SQfjxV9fAdBJq9jDr" local location = "beijing" local language = "zh-Hans" local unit = "c" local start = "0" local days = "5" local url = string.format("https://api.seniverse.com/v3/weather/daily.json?key=%s&location=%s&language=%s&unit=%s&start=%s&days=%s", key, location, language, unit, start, days) whiletruedo http.request("GET", url, nil, nil, nil, nil, cbFnc) sys.wait(30000) end end
local function user_main() sys.wait(10000) sys.taskInit(Test_Task) end