-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
47 lines (40 loc) · 1.25 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
const inquirer = require('inquirer');
const { getFollowers, getFriends, getToken } = require('./twitter-utils');
const { convertFriendsToCSV, saveCSVToFile } = require('./utils');
const questions = [{
type: 'input',
name: 'username',
message: 'What username do you want a list of followers for?',
}, {
type: 'list',
name: 'type',
message: 'What type of report do you want?',
choices: [
'Followers',
'Following',
],
filter: (val) => val.toLowerCase(),
}];
const dataTypes = {
followers: getFollowers,
following: getFriends,
}
async function main() {
let friends = [];
let cursor = -1;
try {
const { type, username } = await inquirer.prompt(questions);
const accessToken = await getToken();
// For info about cursor, see https://developer.twitter.com/en/docs/basics/cursoring
while (cursor !== 0) {
const { users, next_cursor } = await dataTypes[type](accessToken, username, cursor);
friends = friends.concat(users);
cursor = next_cursor;
}
await saveCSVToFile(`./${username}-${type}.csv`, convertFriendsToCSV(friends));
console.log(`Success! Saved ${friends.length} Twitter followers to ./${username}-${type}.csv`);
} catch (err) {
console.log('/// Main Error', err);
}
}
main();