-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathindex.js
101 lines (84 loc) · 1.87 KB
/
index.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const async = require("async");
const axios = require("axios");
const [catalogURL] = process.argv.slice(2);
if (catalogURL == null) {
console.warn("Usage: catalog-crawler <catalog URL>");
process.exit(1);
}
const catalogsChecked = new Set();
const catalogQueue = async.queue(async ({ uri }, callback) => {
try {
return callback(null, await processCatalog(uri));
} catch (err) {
return callback(err);
}
});
const featureQueue = async.queue(async ({ uri, inherited }, callback) => {
try {
return callback(null, await processFeature(uri, inherited));
} catch (err) {
return callback(err);
}
});
const processCatalog = async (uri, inherited = {}) => {
if (catalogsChecked.has(uri)) {
// we've already indexed this catalog
return;
}
catalogsChecked.add(uri);
const {
data: {
contact,
description,
endDate,
features,
geometry,
homepage,
keywords,
links,
name,
provider,
startDate
}
} = await axios.get(uri);
// allow catalog properties to be overridden
const properties = {
...inherited,
contact,
description,
endDate,
geometry,
homepage,
keywords,
provider,
name,
startDate
};
console.log(uri);
console.log(name);
console.log(description);
links.forEach(x =>
catalogQueue.push({
uri: x.uri,
properties
})
);
features.forEach(x => {
// check if the feature needs to be fetched (if it's not fully present)
// emit GeoJSON feature(collections) for each feature
console.log(x.uri);
console.log(x);
if (x.uri) {
featureQueue.push({
uri: x.uri
});
}
});
};
const processFeature = async uri => {
const { data } = await axios.get(uri);
// emit GeoJSON feature(collections) for each feature
console.log(uri);
console.log(data);
};
processCatalog(catalogURL);