-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_scrape_twitter.js
More file actions
74 lines (53 loc) · 1.28 KB
/
node_scrape_twitter.js
File metadata and controls
74 lines (53 loc) · 1.28 KB
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
73
74
/**
* PASS TWO ADDITIONAL OPTIONS IN THIS ORDER:
* twitter_handle, filename[end name with .json]
*/
var TwitterPosts, streamOfTweets;
TwitterPosts = require('twitter-screen-scrape');
var fs = require('fs');
var path = require('path');
streamOfTweets = new TwitterPosts({
username: process.argv[2],
retweets: false
});
store_tweets = [];
streamOfTweets.on('readable', function() {
var time, tweet;
tweet = streamOfTweets.read();
time = new Date(tweet.time * 1000);
console.log(tweet);
/*
console.log([
"KenyaPower_Care's tweet from ",
time.toLocaleDateString(),
" got ",
tweet.favorite,
" favorites, ",
tweet.reply,
" replies, and ",
tweet.retweet,
" retweets"
].join(''));
*/
store_tweets.push({
'tweet': tweet.text,
'time': time.toLocaleDateString()
});
});
function storeTweets(){
var file = path.join(__dirname, 'output', process.argv[3]);
fs.writeFileSync(file,JSON.stringify(store_tweets));
}
streamOfTweets.on('end', function(){
console.log('stream of tweets ended');
storeTweets();
});
streamOfTweets.on('close', function(){
console.log('stream of tweets closed');
storeTweets();
});
process.on('SIGINT', function() {
console.log("Caught interrupt signal");
storeTweets();
process.exit();
});