Repository navigation
Expand file tree
/
Copy pathdatasetParser.js
More file actions
executable file
·45 lines (34 loc) · 1.76 KB
/
Copy pathdatasetParser.js
File metadata and controls
executable file
·45 lines (34 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var cheerio = require('cheerio');
var CKAN = require('./parsers/CKAN/CKAN');
var DKAN = require('./parsers/DKAN/DKAN');
var socrata = require('./parsers/socrata/socrata');
var datatank = require('./parsers/datatank/datatank');
function dataset_parser(options, util, cache) {
this.options = options;
this.util = util;
this.cache = cache;
};
dataset_parser.prototype.start = function start(url, body) {
var dataset_parser = this;
var $ = cheerio.load(body);
var CKANParser = new CKAN(dataset_parser.options , dataset_parser.util, dataset_parser.cache, url);
var DKANParser = new DKAN(dataset_parser.options , dataset_parser.util, dataset_parser.cache, url);
var socrataParser = new socrata(dataset_parser.options , dataset_parser.util, dataset_parser.cache, url);
var datatankParser = new datatank(dataset_parser.options , dataset_parser.util, dataset_parser.cache, url);
CKANParser.check($, function(error, CKANSuccess) {
if (!error) DKANParser.check($, function(error, DKANSuccess){
if (!error) socrataParser.check($, function(error, socrataSuccess){
if (!error) datatankParser.check($, function(error, datatankSuccess){
// The Portal has not been matched with any of the automatic tests, ask for manual entry from the user
var message = CKANSuccess || DKANSuccess || socrataSuccess || datatankSuccess || {type: "warning", message: "invalidPortalURL"};
dataset_parser.util.console(message.type, message.message);
dataset_parser.util.checkValidAddress(dataset_parser.options.prompt.manualPortalURLEntry, function(error, url, body){
if (!error && body) dataset_parser.start(url, body);
});
});
});
});
});
}
// Export the Parser constructor from this module.
module.exports = dataset_parser;