-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (66 loc) · 1.93 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
const Twit = require("twit");
const FS = require("fs");
const config = require("./config");
var T = new Twit({
consumer_key: config.consumer_key,
consumer_secret: config.consumer_secret,
access_token: config.access_token,
access_token_secret: config.access_token_secret,
timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
});
let pyragues = [];
let nextCursor = -1;
function getAllPyragues() {
return getPyragues(nextCursor)
.then(data => {
nextCursor = data.nextCursor;
pyragues = pyragues.concat(data.pyragues);
return getAllPyragues();
})
.catch(error => console.error(`Error: ${error}`));
}
getAllPyragues().then(() => {
console.log("Fin de colecta de pyragues");
let idsMap = pyragues.map(p => p.id_str);
FS.writeFile("pyragues.csv", idsMap.join("\r\n"), err => {
if (err) {
console.error(`Error al generar CSV: ${err}`);
return;
}
});
FS.writeFile("pyragues.json", JSON.stringify(pyragues), err => {
if (err) {
console.error(`Error al generar JSON: ${err}`);
}
});
console.log(`Registros encontrados: ${pyragues.length}`);
});
function getPyragues(cursor) {
return new Promise((resolve, reject) => {
T.get(
"followers/list",
{
screen_name: "horacio_cartes",
skip_status: "true",
count: 200,
cursor: nextCursor
},
(err, data, response) => {
if (err) {
reject(err);
return;
}
let pyragues = data.users.filter(u => {
const fecha = new Date(u.created_at);
return u.profile_image_url ==
"http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png" &&
u.followers_count < 100 &&
u.friends_count < 150 &&
fecha > new Date(2017, 3, 1);
});
let nextCursor = data.next_cursor_str;
resolve({ pyragues, nextCursor });
}
);
});
}