Skip to content

Instantly share code, notes, and snippets.

@hamoid
Last active February 18, 2018 20:15
Show Gist options
  • Save hamoid/00622daee3c687da57ee5a268787e56f to your computer and use it in GitHub Desktop.
Save hamoid/00622daee3c687da57ee5a268787e56f to your computer and use it in GitHub Desktop.
Download Berlin air pollution data from berlin.de
// launch with: node download.js
var http = require('http');
var fs = require('fs');
var start = new Date();
var end = new Date();
start.setDate(end.getDate() - 365);
var download = function() {
if(start <= end) {
var dd = start.getDate();
var mm = start.getMonth()+1; //January is 0!
var yyyy = start.getFullYear();
dd = dd<10 ? '0' + dd : dd;
mm = mm<10 ? '0' + mm : mm;
var f = 'http://www.berlin.de/senuvk/umwelt/luftqualitaet/de/messnetz/tageswerte/download/' +
yyyy + mm + dd + '.html';
console.log('A: ' + f);
var file = fs.createWriteStream('' + yyyy + mm + dd + '.html');
var request = http.get(f, function(response) {
response.pipe(file);
console.log('B: ' + f);
});
start.setDate(start.getDate() + 1);
} else {
process.exit(0);
}
}
setInterval(download, 1500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment