// Actor requests a 16-day forecast from openweathermap API and saves it into a dataset.
const Apify = require('apify');

Apify.main(async () => {
    
    const city = "Rome";
    console.log(city);

    const apiLinkForecast16 = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=' + city + '&cnt=16&appid=b598e22d24d549b196a6e88eb98e292f';
    
    console.log(apiLinkForecast16);
   
    const { body } = await Apify.utils.requestAsBrowser({ url: apiLinkForecast16 });
    var forecast16 = JSON.parse(body);
    console.log(forecast16.list[0]);

    const dataset = await Apify.openDataset('data-rome');

    await dataset.pushData({ dt0: forecast16.list[0].dt, sunrise0: forecast16.list[0].sunrise, sunset0: forecast16.list[0].sunset, temp_day0: forecast16.list[0].temp.day, temp_min0: forecast16.list[0].temp.min, temp_max0: forecast16.list[0].temp.max, pressure0: forecast16.list[0].pressure, humidity0: forecast16.list[0].humidity, speed0: forecast16.list[0].speed, 
                           dt1: forecast16.list[1].dt, sunrise1: forecast16.list[1].sunrise, sunset1: forecast16.list[1].sunset, temp_day1: forecast16.list[1].temp.day, temp_min1: forecast16.list[1].temp.min, temp_max1: forecast16.list[1].temp.max, pressure1: forecast16.list[1].pressure, humidity1: forecast16.list[1].humidity, speed1: forecast16.list[1].speed,     
                           dt2: forecast16.list[2].dt, sunrise2: forecast16.list[2].sunrise, sunset2: forecast16.list[2].sunset, temp_day2: forecast16.list[2].temp.day, temp_min2: forecast16.list[2].temp.min, temp_max2: forecast16.list[2].temp.max, pressure2: forecast16.list[2].pressure, humidity2: forecast16.list[2].humidity, speed2: forecast16.list[2].speed,     
                           dt3: forecast16.list[3].dt, sunrise3: forecast16.list[3].sunrise, sunset3: forecast16.list[3].sunset, temp_day3: forecast16.list[3].temp.day, temp_min3: forecast16.list[3].temp.min, temp_max3: forecast16.list[3].temp.max, pressure3: forecast16.list[3].pressure, humidity3: forecast16.list[3].humidity, speed3: forecast16.list[3].speed,     
                           dt4: forecast16.list[4].dt, sunrise4: forecast16.list[4].sunrise, sunset4: forecast16.list[4].sunset, temp_day4: forecast16.list[4].temp.day, temp_min4: forecast16.list[4].temp.min, temp_max4: forecast16.list[4].temp.max, pressure4: forecast16.list[4].pressure, humidity4: forecast16.list[4].humidity, speed4: forecast16.list[4].speed,     
                           dt5: forecast16.list[5].dt, sunrise5: forecast16.list[5].sunrise, sunset5: forecast16.list[5].sunset, temp_day5: forecast16.list[5].temp.day, temp_min5: forecast16.list[5].temp.min, temp_max5: forecast16.list[5].temp.max, pressure5: forecast16.list[5].pressure, humidity5: forecast16.list[5].humidity, speed5: forecast16.list[5].speed,     
                           dt6: forecast16.list[6].dt, sunrise6: forecast16.list[6].sunrise, sunset6: forecast16.list[6].sunset, temp_day6: forecast16.list[6].temp.day, temp_min6: forecast16.list[6].temp.min, temp_max6: forecast16.list[6].temp.max, pressure6: forecast16.list[6].pressure, humidity6: forecast16.list[6].humidity, speed6: forecast16.list[6].speed,     
                           dt7: forecast16.list[7].dt, sunrise7: forecast16.list[7].sunrise, sunset7: forecast16.list[7].sunset, temp_day7: forecast16.list[7].temp.day, temp_min7: forecast16.list[7].temp.min, temp_max7: forecast16.list[7].temp.max, pressure7: forecast16.list[7].pressure, humidity7: forecast16.list[7].humidity, speed7: forecast16.list[7].speed,     
                           dt8: forecast16.list[8].dt, sunrise8: forecast16.list[8].sunrise, sunset8: forecast16.list[8].sunset, temp_day8: forecast16.list[8].temp.day, temp_min8: forecast16.list[8].temp.min, temp_max8: forecast16.list[8].temp.max, pressure8: forecast16.list[8].pressure, humidity8: forecast16.list[8].humidity, speed8: forecast16.list[8].speed,     
                           dt9: forecast16.list[9].dt, sunrise9: forecast16.list[9].sunrise, sunset9: forecast16.list[9].sunset, temp_day9: forecast16.list[9].temp.day, temp_min9: forecast16.list[9].temp.min, temp_max9: forecast16.list[9].temp.max, pressure9: forecast16.list[9].pressure, humidity9: forecast16.list[9].humidity, speed9: forecast16.list[9].speed,     
                           dt10: forecast16.list[10].dt, sunrise10: forecast16.list[10].sunrise, sunset10: forecast16.list[10].sunset, temp_day10: forecast16.list[10].temp.day, temp_min10: forecast16.list[10].temp.min, temp_max10: forecast16.list[10].temp.max, pressure10: forecast16.list[10].pressure, humidity10: forecast16.list[10].humidity, speed10: forecast16.list[10].speed,     
                           dt11: forecast16.list[11].dt, sunrise11: forecast16.list[11].sunrise, sunset11: forecast16.list[11].sunset, temp_day11: forecast16.list[11].temp.day, temp_min11: forecast16.list[11].temp.min, temp_max11: forecast16.list[11].temp.max, pressure11: forecast16.list[11].pressure, humidity11: forecast16.list[11].humidity, speed11: forecast16.list[11].speed,     
                           dt12: forecast16.list[12].dt, sunrise12: forecast16.list[12].sunrise, sunset12: forecast16.list[12].sunset, temp_day12: forecast16.list[12].temp.day, temp_min12: forecast16.list[12].temp.min, temp_max12: forecast16.list[12].temp.max, pressure12: forecast16.list[12].pressure, humidity12: forecast16.list[12].humidity, speed12: forecast16.list[12].speed,     
                           dt13: forecast16.list[13].dt, sunrise13: forecast16.list[13].sunrise, sunset13: forecast16.list[13].sunset, temp_day13: forecast16.list[13].temp.day, temp_min13: forecast16.list[13].temp.min, temp_max13: forecast16.list[13].temp.max, pressure13: forecast16.list[13].pressure, humidity13: forecast16.list[13].humidity, speed13: forecast16.list[13].speed,     
                           dt14: forecast16.list[14].dt, sunrise14: forecast16.list[14].sunrise, sunset14: forecast16.list[14].sunset, temp_day14: forecast16.list[14].temp.day, temp_min14: forecast16.list[14].temp.min, temp_max14: forecast16.list[14].temp.max, pressure14: forecast16.list[14].pressure, humidity14: forecast16.list[14].humidity, speed14: forecast16.list[14].speed,     
                           dt15: forecast16.list[15].dt, sunrise15: forecast16.list[15].sunrise, sunset15: forecast16.list[15].sunset, temp_day15: forecast16.list[15].temp.day, temp_min15: forecast16.list[15].temp.min, temp_max15: forecast16.list[15].temp.max, pressure15: forecast16.list[15].pressure, humidity15: forecast16.list[15].humidity, speed15: forecast16.list[15].speed     
                           });

});