-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
41 lines (36 loc) · 1.36 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
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
//const fetch = require('node-fetch'); // Make sure to install if not already present
module.exports = {
get: function() {
const promise = new Promise(function(resolve, reject) {
resolve(require('./data/service_info.json'));
});
return promise;
},
getRegionCodeToNameMap: function() {
return new Promise(async function(resolve, reject) {
const regionCodeToNameMap = {};
try {
const htmlContent = await fetch('https://docs.aws.amazon.com/general/latest/gr/rande.html').then(res => res.text());
const dom = new JSDOM(htmlContent);
const doc = dom.window.document;
const table = doc.querySelector('.table-container');
if (table) {
const rows = table.querySelectorAll('tr');
rows.forEach(row => {
const columns = row.querySelectorAll('td');
if (columns.length >= 2) {
const regionName = columns[0].textContent.trim();
const regionCode = columns[1].textContent.trim();
regionCodeToNameMap[regionCode] = regionName;
}
});
}
resolve(regionCodeToNameMap);
} catch (error) {
reject(error);
}
});
}
};