Created
April 27, 2017 13:46
-
-
Save JustPingo/2d2bcd31ee61d5180adfd38245c1b34a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TwitterSpy.js | |
// npm install twitter | |
// npm install prompt | |
var requestCooldown = 5; // in seconds | |
var Twitter = require('Twitter'); | |
var prompt = require('prompt'); | |
// Provide your Twitter API keys in this object | |
var client = new Twitter({ | |
consumer_key: '', | |
consumer_secret: '', | |
access_token_key: '', | |
access_token_secret: '' | |
}); | |
function sleep(seconds) { | |
var waitTill = new Date(new Date().getTime() + seconds * 1000); | |
while (waitTill > new Date()) {} | |
} | |
function performSearch(u1, u2) { | |
var u1followers = [ ]; | |
var u1followings = [ ]; | |
var u2id; | |
console.log("Downloading u1's followers..."); | |
var followersHandling = function(error, followers, response) { | |
if (error) throw error; | |
u1followers = u1followers.concat(followers.ids); | |
if (followers.next_cursor != 0) { | |
sleep(requestCooldown); | |
client.get("followers/ids", { screen_name: u1, cursor: followers.next_cursor }, followersHandling); | |
} else { | |
console.log("Downloading u1's followings..."); | |
var followingsHandling = function(error, followings, response) { | |
if (error) throw error; | |
u1followings = u1followings.concat(followings.ids); | |
if (followings.next_cursor != 0) { | |
sleep(requestCooldown); | |
client.get("friends/ids", { screen_name: u1, cursor: followings.next_cursor }, followingsHandling); | |
} else { | |
console.log("Resolving u2's id..."); | |
client.get("users/show", { screen_name: u2 }, function(error, user, response) { | |
if (error) throw error; | |
u2id = user.id; | |
console.log(""); | |
if (u1followings.findIndex(function(v, i, o) { return v == u2id }) != -1) { | |
console.log(u1 + " follows " + u2); | |
} | |
if (u1followers.findIndex(function(v, i, o) { return v == u2id }) != -1) { | |
console.log(u2 + " follows " + u1); | |
} | |
}); | |
} | |
} | |
client.get("friends/ids", { screen_name: u1 }, followingsHandling); | |
} | |
} | |
client.get("followers/ids", { screen_name: u1 }, followersHandling); | |
} | |
console.log("The application will use userOne as a base."); | |
console.log("Please make sure userOne is not private."); | |
prompt.start(); | |
prompt.get(['userOne', 'userTwo'], function (err, result) { | |
performSearch(result.userOne, result.userTwo); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment