-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnubes_players.js
66 lines (62 loc) · 2.21 KB
/
nubes_players.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
56
57
58
59
60
61
62
63
64
65
66
const fetch = require("node-fetch");
const parser = require("node-html-parser")
const fs = require('fs');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const sitesNumber = async () => {
try {
const request = await fetch("https://new.margonem.pl/ladder/players,Nubes?page=1");
const data = await request.text();
const document = parser.parse(data);
const sites = parseInt(document.querySelector(".total-pages a").text, 10);
return czlenie(sites);
} catch (err) {
console.log(err);
return setTimeout(sitesNumber, 100);
}
}
const czlenie = async strony => {
const ids = fs.readFileSync("nubes", 'utf8').split(",");
const newCzlenie = [];
try {
for (let i = 1; i <= strony; i++) {
console.log(`Strona: ${i}`);
const site = await fetch(`https://new.margonem.pl/ladder/players,Nubes?page=${i}`);
const data = await site.text();
const document = parser.parse(data);
const allPlayers = Array.from(document.querySelectorAll("table tbody tr"));
for (let player of allPlayers) {
const [idConta, ] = player.childNodes[3].childNodes[1].rawAttrs.match(/(\d+)/g);
if (!ids.includes(idConta)) {
// newCzlenie.push(idConta);
ids.push(idConta);
}
}
}
} catch (err) {
console.log(err);
} finally {
fs.writeFileSync("nubes", ids);
//if (newCzlenie.length) await sendCzlenie(newCzlenie);
//sitesNumber();
console.log(ids.length-1);
}
}
const sendCzlenie = async czlenie => {
const wh = "https://discordapp.com/api/webhooks/696732265920593921/UfHxYF3p9bRt_3PTk3MpQbbUSfZSnfhGlbJP5ze2BcCiEKYo6HT6N266l57y7xL7IxIX";
for (let czlen of czlenie) {
try {
await fetch(wh, {
method: "POST",
headers: {
"Content-type": "application/json"
},
body: JSON.stringify({
content: `https://www.margonem.pl/?task=profile&id=${czlen}`
})
})
} catch(err) {
console.log("Nie wysłałem człenia");
}
}
}
sitesNumber();