-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
134 lines (110 loc) · 3.42 KB
/
main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const Instagram = require("instagram-web-api");
var fs = require("fs");
const { username, password } = process.env;
const client = new Instagram({ username: 'USERNAME', password: 'PASSWORD' })
async function run() {
await client.login();
const me = await client.getUserByUsername({
username: client.credentials.username,
});
const followerCount = me.edge_followed_by.count;
const userID = me.id;
var followersList = [];
const followers = await client.getFollowers({
userId: userID,
first: 50,
});
var end_cursor = followers.page_info.end_cursor;
for (var i = 0; i < followers.data.length; i++) {
var info = [followers.data[i].username, followers.data[i].id];
followersList.push(info)
}
if (followerCount > 50) {
for (var j = followerCount - 50; j > 0; j -= 50) {
const followers2 = await client.getFollowers({
userId: userID,
first: 50,
after: end_cursor,
});
end_cursor = followers2.page_info.end_cursor;
for (var i = 0; i < followers2.data.length; i++) {
var info = [followers2.data[i].username, followers2.data[i].id];
followersList.push(info);
}
}
////////////////////////
var file = fs.createWriteStream("followers.txt");
file.on("error", function (err) {
/* error handling */
});
followersList.forEach(function (v) {
file.write(v.join(", ") + "\n");
});
file.end();
//////////////////////////
}
const followingCount = me.edge_follow.count;
var followingList = [];
const followings = await client.getFollowings({
userId: userID,
first: 50,
});
var end_cursor = followings.page_info.end_cursor;
for (var i = 0; i < followings.data.length; i++) {
var info = [followings.data[i].username, followings.data[i].id];
followingList.push(info);
}
if (followingCount > 50) {
for (var j = followingCount - 50; j > -50; j -= 50) {
const followings2 = await client.getFollowings({
userId: userID,
first: 50,
after: end_cursor,
});
end_cursor = followings2.page_info.end_cursor;
for (var i = 0; i < followings2.data.length; i++) {
var info = [followings2.data[i].username, followings2.data[i].id];
followingList.push(info);
}
}
////////////////////////
var file = fs.createWriteStream('following.txt');
file.on("error", function (err) {
/* error handling */
});
followingList.forEach(function (v) {
file.write(v.join(", ") + "\n");
});
file.end();
//////////////////////////
}
{
var notFollowingBackList = [];
for (var i = 0; i < followingList.length; i++) {
var isFollowingBack = false;
for (var j = 0; j < followersList.length; j++) {
if (
followingList[i][0] == followersList[j][0] &&
followingList[i][1] == followersList[j][1]
) {
isFollowingBack = true;
}
}
if (isFollowingBack == false) {
notFollowingBackList.push(followingList[i]);
}
}
////////////////////////
var file = fs.createWriteStream("not-following-back.txt");
file.on("error", function (err) {
/* error handling */
});
notFollowingBackList.forEach(function (v) {
file.write(v.join(", ") + "\n");
});
file.end();
//////////////////////////
}
}
run()
//sort()