'use strict'; (function() { var stations = require('./server/stations'); var meteo = require('./server/meteo'); var assemble = require('./server/assemble'); var IO = require('./server/io'); var chalk = require('chalk'); function next(index) { if (index >= stations.ids.length) { console.log(chalk.green("Finished.")); return; } console.log('=== Starting next promise chain.'); var station = 46026 //stations.ids[index]; Promise.resolve() //===== Download // .then(stations.getMetadata.bind(null, station)) // .then(meteo.getAllYears.bind(null, station, 1982, 2014)) // .then(meteo.getAllMonths.bind(null, station, 2015)) // .then(meteo.getAllNewest.bind(null, station, 2015)) //===== Parse // .then(stations.parseStation.bind(null, station)) // .then(meteo.parseAllMonths.bind(null, 46026, 2015)) // .then(meteo.parseAllYears.bind(null, station, 1982, 2014)) //===== Assemble .then(assemble.read.bind(null, station, 2015)) .then(assemble.getAverages) // .then(function() { console.log('something') }) //===== Flow control .then(function() { console.log('=== Chain complete.\n'); }) // .then(next.bind(null, index + 1)) .catch(IO.error); }; // TODO remove previous years from file, such as 46026-2015 shouldn't have data from 2014. next(0); })();