local lat = jarvis.memory.recall("weather.lat") local lon = jarvis.memory.recall("weather.lon") local city = jarvis.memory.recall("weather.city") if not lat or not lon then local ip = jarvis.http.json("https://ipinfo.io/json") if not ip or not ip.loc then return jarvis.cmd.error("Не получилось узнать местоположение.") end lat, lon = ip.loc:match("^([^,]+),(.*)$") city = ip.city or "ваш город" jarvis.memory.remember("weather.lat", lat) jarvis.memory.remember("weather.lon", lon) jarvis.memory.remember("weather.city", city) end local url = string.format( "https://api.open-meteo.com/v1/forecast?latitude=%s&longitude=%s&daily=temperature_2m_max,temperature_2m_min&timezone=auto&forecast_days=7", lat, lon ) local data = jarvis.http.json(url) if not data or not data.daily or not data.daily.temperature_2m_max then return jarvis.cmd.error("Прогноз недоступен.") end local maxes = data.daily.temperature_2m_max local mins = data.daily.temperature_2m_min -- Find min and max of the week local week_max, week_min = -100, 100 for i = 1, #maxes do if maxes[i] > week_max then week_max = maxes[i] end if mins[i] < week_min then week_min = mins[i] end end local line = string.format("Неделя в %s: днём от %d до %d градусов, ночью до %d.", city or "вашем городе", math.floor(week_min + 0.5), math.floor(week_max + 0.5), math.floor(week_min + 0.5)) return jarvis.cmd.ok(line)