Utilizing the openweathermap api, I am retrieving a 5-day/3-hour forecast here.
The API call provides multiple results for each day with data available every 3 hours. For the full JSON response, you can access it here. Please note that the API key is only for testing purposes.
{
"cod": "200",
"message": 0.0034,
"cnt": 37,
"list": [
{
"dt": 1518512400,
"main": {
"temp": 23.79,
"temp_min": 21.5,
...
// Remaining JSON data not included for brevity
My issue arises as I specifically require data for the "12:00" time slot for each day, yet the returned data contains multiple time slots throughout the day.
I've attempted the following approach but have not been successful:
getData(){
var arraycontainsMidday;
this.http.get('https://api.openweathermap.org/data/2.5/forecast?id=3362024&APPID=bbcf57969e78d1300a815765b7d587f0&units=metric').map(res=>res.json()).subscribe(data => {
this.items = data;
for(var i = 0; i < this.items.list.length; i++){
this.dates = this.items.list[i].dt_txt.substring(10);
this.temps = this.items.list[i].main;
//if 12 o'clock middat is found
arraycontainsMidday = (this.dates.indexOf("12:00:00") > -1);
}
for(var j = 0; j < this.items.list.length; j++){
this.temps = this.items.list[j].main.temp;
}
})
}