-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (72 loc) · 2.23 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
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
const { parseStream } = require("fast-csv");
const fs = require("fs");
var oldFollowingStream = fs.createReadStream("./data/old/IG-following.csv");
var oldFollowersStream = fs.createReadStream("./data/old/IG-followers.csv");
var newFollowingStream = fs.createReadStream("./data/new/IG-following.csv");
var newFollowersStream = fs.createReadStream("./data/new/IG-followers.csv");
const oldFollowing = [];
const oldFollowers = [];
const newFollowing = [];
const newFollowers = [];
const readOldFollowing = new Promise((resolve) => {
parseStream(oldFollowingStream, { headers: true })
.on("data", function (data) {
oldFollowing.push(data);
})
.on("end", function () {
resolve();
});
});
const readOldFollowers = new Promise((resolve) => {
parseStream(oldFollowersStream, { headers: true })
.on("data", function (data) {
oldFollowers.push(data);
})
.on("end", function () {
resolve();
});
});
const readNewFollowing = new Promise((resolve) => {
parseStream(newFollowingStream, { headers: true })
.on("data", function (data) {
newFollowing.push(data);
})
.on("end", function () {
resolve(newFollowing);
});
});
const readNewFollowers = new Promise((resolve) => {
parseStream(newFollowersStream, { headers: true })
.on("data", function (data) {
newFollowers.push(data);
})
.on("end", function () {
resolve();
});
});
const comparingOldToNewData = async () => {
Promise.all([
readOldFollowing,
readOldFollowers,
readNewFollowing,
readNewFollowers,
]).then(() => {
console.log(
"Has number of Following changed?",
JSON.stringify(oldFollowing) !== JSON.stringify(newFollowing)
);
console.log(
"Has number of Followers changed?",
JSON.stringify(oldFollowers) !== JSON.stringify(newFollowers)
);
const result = oldFollowers.filter((person) => {
return !newFollowers.find(
(element) => JSON.stringify(element) == JSON.stringify(person)
);
});
console.log("-----------------------------------------------");
console.log(result.length, "People unfollowed you");
result.map((person) => console.log(person.userName, "Unfollowed you"));
});
};
comparingOldToNewData();