-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (26 loc) · 1.25 KB
/
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
31
32
33
34
35
36
37
const { formatDuration, nodeToPost, getPostUserName, shouldLikesPosts, getUserInformation, likeUserPosts } = require('./helpers');
const { MAX_LIKES_PER_SESSION } = require('./contants');
const setup = require('./setup');
(async () => {
const start = Date.now();
const { browser, page } = await setup('https://www.instagram.com/explore/tags/drawing');
const nodes = await page.evaluate(() => _sharedData.entry_data.TagPage[0].graphql.hashtag.edge_hashtag_to_media.edges);
const posts = nodes.map(nodeToPost).filter((post, index, arr) => arr.findIndex(item => item.owner_id === post.owner_id) >= index);
console.log( posts );
let usersLikedCount = 0;
let postsLikedCount = 0;
while (posts.length) {
const post = posts.shift();
const userName = await getPostUserName(post, page);
if (userName === null) continue;
const user = await getUserInformation(userName, page);
if (user === null) continue;
if (shouldLikesPosts(user)) {
usersLikedCount += 1;
postsLikedCount += await likeUserPosts(user, page);
if (postsLikedCount >= MAX_LIKES_PER_SESSION) break;
}
}
console.log( `Liked ${postsLikedCount} posts from ${usersLikedCount} users in ${formatDuration(Date.now() - start)}` );
await browser.close();
})();