You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
2.0 KiB

'use strict'
var downloader = require('./downloader');
var IO = require('./io');
var xml2js = require ('xml2js');
// var dir = 'data/stations/';
module.exports = {
dirs: {
xml: 'data/stations/xml/',
json: 'data/stations/json/'
},
/**
* Add station IDs here, A-Z 0-9
*/
ids: [
// 'ANVC1',
// 'BDXC1',
// 'CECC1',
// 'CPXC1',
// 'HBYC1',
// 'ICAC1',
// 'NTBC1',
// 'PRYC1',
// 'PTGC1',
'46011',
'46012',
'46013',
'46014',
'46022',
'46025',
'46027',
'46028',
'46042',
'46053',
'46054',
'46092',
'46213',
'46214',
'46215',
'46216',
'46217',
'46221',
'46223',
'46225',
'46232',
'46234',
'46237',
'46239',
'46240',
'46242',
'46244',
'46253',
'46254',
'46256',
'46257'
],
/**
* Downloads each station's data XML.
*/
getMetadata: function(station) {
var url = 'http://www.ndbc.noaa.gov/get_observation_as_xml.php?station=' + station;
return downloader.download(url, module.exports.dirs.xml + station + '.xml');
},
/**
*
*/
parse: function(xml) {
return new Promise(function(resolve) {
xml2js.parseString(xml, function(err, json) {
var str = null;
// Do not stringify if null.
if (json) {
str = JSON.stringify(json.observation.$)
}
resolve(str);
});
});
},
/**
*
*/
parseStation: function(station) {
return IO.read(module.exports.dirs.xml + station + '.xml')
.then(module.exports.parse)
.then(function(str) {
IO.write(module.exports.dirs.json + station + '.json', str)
})
},
};