-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.js
92 lines (86 loc) · 2.56 KB
/
helper.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Variables
const axios = require("axios");
const cheerio = require("cheerio");
const fs = require("fs");
const config = require("./config");
const Discord = require("discord.js");
const webhookClient = new Discord.WebhookClient(
config.webhookUrl.split("/")[5],
config.webhookUrl.split("/")[6]
);
completed = [];
function getPostCount(account) {
console.log(` [Info] Account ${account}`);
axios.get(account).then((response) => {
if (response.status === 200) {
const data = cheerio.load(response.data);
const t = data(".active").text();
newData = t.match(/\d+/g);
if (newData[1]) {
scrapePosts(account, Math.round(((parseInt(newData[0]) + parseInt(newData[1]) - 32) / 20) + 2),);
} else {
const calc = Math.round((parseInt(newData[0]) - 32) / 20) + 2
if (calc < 1) {
scrapePosts(account, 1);
} else {
scrapePosts(account, calc);
}
}
}
});
}
function scrapePosts(result, maxPage) {
for (let i = 1; i < maxPage; i++)
axios
.get(`${result}?page=${i}`)
.then((resp) => {
console.log("\x1b[32m", `[Scraper] : Scraped ${resp.config.url}`);
const d = cheerio.load(resp.data);
d("a").each((_index, value) => {
if (d(value).attr("href").includes("entry"))
checkPost(d(value).attr("href"), result, resp.config.url);
});
})
.catch(() => {});
}
function checkPost(url) {
axios
.get(`https://weheartit.com/${url}`)
.then((resp) => {
const data = cheerio.load(resp.data);
data(".cel img").each((_i, img) => {
if (
img.attribs.src.includes("avatar") ||
img.attribs.src.includes("weheartit") ||
img.attribs.src.includes("superthumb") ||
img.attribs.src.includes("ajax") ||
img.attribs.src.includes("pink_heart")
) {
return;
} else {
if (completed.includes(img.attribs.src.split("/images/")[1].split("/")[0])) {
return;
} else {
fs.appendFileSync("./url1.txt", `${img.attribs.src}\n`);
completed.push(img.attribs.src.split("/images/")[1].split("/")[0])
send(img.attribs.src);
}
}
});
})
.catch(() => {
checkPost(url)
});
}
function send(url) {
webhookClient.send(url, {
username: "icon",
avatarURL: "https://i.imgur.com/9aYk9Xz.png",
});
}
setInterval(() => {
completed = []
}, 12000)
module.exports = {
getPostCount,
};