r6s-stats-api
Version:
An api for fetching player statistics from Rainbow Six Siege
40 lines (29 loc) • 905 B
JavaScript
const cheerio = require('cheerio');
const exec = require('./modules/exec-fetch');
const filterArray = require('./modules/filterarray');
module.exports = async function (url) {
let result = [];
let rank = [];
const data = await exec(url);
if (!data) {
result[0] = 'timeout';
return result;
}
const $ = cheerio.load(data);
$('#profile .r6-season__stats').each(function (i, elem) {
rank.push(filterArray($(this).text().split('\n')));
});
let imgurl = $('img').map(function () {
return $(this).attr('src');
});
let header = imgurl.toArray()[0];
result.push(header);
if (header.indexOf('avatars') === -1 && header.indexOf('xbox') === -1) {
result[0] = 'error';
return result;
}
result.push(rank[2]);
//console.log('rank', rank);
//console.log('result', result);
return result;
};