-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape-info.js
55 lines (42 loc) · 1.9 KB
/
scrape-info.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
// Created by J. Eric Hartzog on 7/19/17
const scrapeInfo = async browser => {
const sections = await browser.elements('div.section-cardinal.quarter');
const getNumberForSection = async section => {
const sectionId = sections.value[section].ELEMENT;
const numberElm = await browser.elementIdElement(sectionId, '.cardinal-numeral');
const numberText = await browser.elementIdText(numberElm.value.ELEMENT);
const number = Number.parseFloat(numberText.value);
if (Number.isNaN(number)) {
throw new Error('Found NaN while scraping, giving up attempt');
}
return number;
}
const getCurrentNumberInstances = async section => {
const sectionId = sections.value[3].ELEMENT;
const numberElm = await browser.elementIdElement(sectionId, 'input');
const numberText = await browser.elementIdAttribute(numberElm.value.ELEMENT, 'value');
const number = Number.parseInt(numberText.value, 10);
if (Number.isNaN(number)) {
throw new Error('Found NaN while scraping, giving up attempt');
}
return number;
}
const getContainerSize = async section => {
const sectionId = sections.value[3].ELEMENT;
const sizeElm = await browser.elementIdElement(sectionId, '.cardinal-subtext');
const sizeText = await browser.elementIdText(sizeElm.value.ELEMENT);
const size = sizeText.value.split(' ')[0];
if (size == null || size.length <= 0) {
throw new Error('Found NaN while scraping, giving up attempt');
}
return size.toLowerCase();
}
return {
connections: await getNumberForSection(0),
cpu: await getNumberForSection(1),
memory: await getNumberForSection(2),
containers: await getCurrentNumberInstances(),
containerSize: await getContainerSize(),
}
};
module.exports = scrapeInfo;