x-weather
Version:
A collection of web components implementing portions of the OpenWeatherMap API.
2 lines (1 loc) • 1.06 kB
JavaScript
import"./utilities.js";import"./types.js";import{updateForecastWeather as t}from"./updateForecastWeather.js";var e=t=>{var{appid:e,host:a,latitude:o,longitude:n,placename:r}=t;if(e&&a&&o&&n&&r)return(t=>{var{appid:e,host:a,latitude:o,longitude:n,placename:r}=t,i="https://".concat(a,"/data/2.5/forecast/daily?lat=").concat(o,"&lon=").concat(n,"&mode=json&units=metric&cnt=14&appid=").concat(e);return fetch(i,{method:"GET"}).then(t=>{if(t.ok)return t.json()})})({appid:e,host:a,latitude:o,longitude:n,placename:r}).then(t=>{if(!t)throw new Error("failed to get result from the forecast weather service using: appid: ".concat(e,", host: ").concat(a,", latitude: ").concat(o,", longitude: ").concat(n,", placename: ").concat(r));var{city:i,cod:c,message:p,cnt:l,list:d}=t;return JSON.stringify(d)})},a=a=>{var{appid:o,host:n}=a;return(a,r)=>{var{latitude:i,longitude:c,placename:p}=r().weather.preferences.location;return e({appid:o,host:n,latitude:i,longitude:c,placename:p}).then(e=>{e.length>0&&a(t({json:e}))})}};export default a;export{a as getForecastWeather};