-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetSyoteIds.js
36 lines (32 loc) · 915 Bytes
/
getSyoteIds.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
const fetch = require('node-fetch');
const cheerio = require('cheerio');
module.exports = async endpoint => {
try {
const response = await fetch(endpoint);
const body = await response.text();
const $ = cheerio.load(body);
const firstRowInputs = $('#taulukko tbody tr')
.first()
.find('input');
// Collect ids here
const ids = [];
firstRowInputs.each((i, elem) => {
ids.push($(elem).attr('id'));
});
// Get only the syote IDs from the element ids
// ID: <vartion_numero>_<syote_id>-<tarkiste/arvo>
const syoteIds = ids
.map(
id =>
id
.split('_')
.slice(-1)[0] // Alaviivan jälkeen
.split('-')[0] // Ennen väliviivaa
)
.filter((v, i, a) => a.indexOf(v) === i); // Suodata duplikaatit
return syoteIds;
} catch (err) {
console.error(err);
process.exit(1);
}
};