-
Notifications
You must be signed in to change notification settings - Fork 67
/
many-blocks.js
48 lines (43 loc) · 1.28 KB
/
many-blocks.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
'use strict';
/**
* Script to block a list of screen names using credentials for a given user id
*/
var twitterAPI = require('node-twitter-api'),
fs = require('fs'),
util = require('./util'),
setup = require('./setup');
var twitter = setup.twitter,
logger = setup.logger,
BtUser = setup.BtUser,
TwitterUser = setup.TwitterUser,
BlockBatch = setup.BlockBatch,
Block = setup.Block;
if (process.argv.length < 4) {
logger.fatal('Usage: js many-blocks.js UID FILE_SCREEN_NAMES');
process.exit();
}
BtUser
.findByPk(process.argv[2])
.then(function(user) {
var filename = process.argv[3];
var accessToken = user.access_token;
var accessTokenSecret = user.access_token_secret;
var targets = fs.readFileSync(filename)
.toString().replace(/\n$/, '').split('\n');
util.slowForEach(targets, 120, function(target) {
logger.info('Blocking ' + target);
twitter.blocks('create', {
user_id: target,
skip_status: 1
}, accessToken, accessTokenSecret,
function(err, results) {
if (err) {
logger.error('Error blocking: %j', err);
} else {
logger.info('Blocked ' + target);
}
});
});
}).catch(function(err) {
logger.error(err);
});