-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (26 loc) · 925 Bytes
/
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
"use strict";
const ap_url = 'https://penr.stachanov.com';
const axios = require('axios');
const cheerio = require('cheerio');
class AP {
getCurrentAvailability() {
return axios({
url: ap_url + '/penr/currentAvailability/index'
}).then(function(response) {
const $ = cheerio.load(response.data);
const table = $('#currentAvailability');
let results = [];
table.find('tbody > tr').each(function(i, el) {
const row = $(el);
results.push({
status: row.attr('class'),
name: row.find('.name').text().trim(),
availability: row.find('td:nth-child(2)').text(),
spaces: parseInt(row.find('td.number').text().replace(/\./g,'')) || 0,
});
});
return results;
});
}
}
module.exports = AP;