Last active
February 18, 2018 20:15
-
-
Save hamoid/00622daee3c687da57ee5a268787e56f to your computer and use it in GitHub Desktop.
Download Berlin air pollution data from berlin.de
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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