Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

api - How to get daily forecast for 7 days WEATHERAPI

I read this doc. https://openweathermap.org/api/one-call-api

https://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${lon}&appid=${appid}&units=metric

make an API call and get current & daily data and here what daily data is:

daily: Array(8)
  0: {dt: 1611057600, sunrise: 1611042930, sunset: 1611073597, temp: {…}, feels_like: {…}, …}
  1: {dt: 1611144000, sunrise: 1611129267, sunset: 1611160097, temp: {…}, feels_like: {…}, …}
  2: {dt: 1611230400, sunrise: 1611215602, sunset: 1611246597, temp: {…}, feels_like: {…}, …}
  3: {dt: 1611316800, sunrise: 1611301933, sunset: 1611333099, temp: {…}, feels_like: {…}, …}
  4: {dt: 1611403200, sunrise: 1611388263, sunset: 1611419602, temp: {…}, feels_like: {…}, …}
  5: {dt: 1611489600, sunrise: 1611474590, sunset: 1611506106, temp: {…}, feels_like: {…}, …}
  6: {dt: 1611576000, sunrise: 1611560914, sunset: 1611592611, temp: {…}, feels_like: {…}, …}
  7: {dt: 1611662400, sunrise: 1611647236, sunset: 1611679116, temp: {…}

0:
  clouds: 100
  dew_point: 6.92
  dt: 1611057600
  feels_like: {day: 4.85, night: 4.15, eve: 3.98, morn: 5.82}
  humidity: 76
  pop: 1
  pressure: 1006
  rain: 7.51
  sunrise: 1611042930
  sunset: 1611073597
  temp: {day: 10.85, min: 9.13, max: 11.31, night: 10.76, eve: 10.3, …}
  uvi: 0.28
  weather: [{…}]
  wind_deg: 233
  wind_speed: 7.51
  __proto__: Object

And I thought that 0[dt] = day of the week but that's not true, that's just a information of todays' day

I had a loop: {new Date(el.dt).getDate()} {new Date(el.dt).getHours()}-{new Date(el.dt).getMinutes()} {el.dt}

19 18-30 1611057600
19 18-32 1611144000
19 18-33 1611230400
19 18-35 1611316800
19 18-36 1611403200
19 18-38 1611489600
19 18-39 1611576000
19 18-41 1611662400

I want to get data from each day of the week but I don't know how to do it.

WeatherApi has this API: https://openweathermap.org/forecast16 and here we have a param "cnt" where we can specify how many days we want to get but this API requires a paid version. Since my apikey doesn't work with this api.

So, if someone know how to do it, it would be very nice.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...