-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
67 lines (59 loc) · 2.11 KB
/
app.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
var argv = require('optimist').argv
var colors = require('colors');
var meetup = require('./lib/meetup');
var twitter = require('./lib/twitter');
var Cache = require('./lib/cache');
var pollMinutes = (argv.p) ? argv.p : 60;
var twit = new twitter.createConnection({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
var meet = meetup.createConnection(process.env.MEETUP_API_KEY);
function run() {
var cache = new Cache();
console.log('contacting meetup.com');
console.log('requesting twitterIds for group: ' + process.env.MEETUP_GROUP_NAME);
meet.getMemberTwitterIds(process.env.MEETUP_GROUP_NAME, function(err, resp) {
if(!err) {
console.log('retreived ' + resp.length + ' twitter ids from meetup');
for(var i=0; i<resp.length; i++) {
// need to clean the names
var raw = resp[i];
if(raw.indexOf('\.com\/') !== -1) {
raw = raw.split('\.com\/')[1];
}
if(raw) cache.add('meetup', raw);
}
console.log('contacting twitter.com');
twit.getFollowedNames(function(err, resp) {
if(!err) {
console.log('retreived ' + resp.length + ' twitter ids from twitter');
for(var i=0; i<resp.length; i++) {
cache.add('twitter', resp[i]);
}
var diff = cache.diff();
if(diff.length > 0) {
console.log('attempting to follow ' + diff.length + ' twitter names (' + diff.join() + ')');
twit.followNames(diff, function(err, resp) {
if(!err) {
console.log('done!')
} else {
console.log('error'.red + ' ' + err.message);
}
});
} else {
console.log('nobody to follow');
}
} else {
console.log('error'.red + ' ' + err.message);
}
});
} else {
console.log('error'.red + ' ' + err.message);
}
});
}
var poll = setInterval(run, pollMinutes * 60000);
run();