forked from edsu/earls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.js
executable file
·41 lines (33 loc) · 1001 Bytes
/
load.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
#!/usr/bin/env node
/*
* This script is useful if you have some tweets in a file (that you
* created with twarc) and you would like to load them into your
* earls instance. This can happen when you haven't been running earls
* the whole duration of the event that you are tracking.
*/
var fs = require('fs');
var earls = require('./earls');
var readline = require('readline');
var filename = process.argv[2];
var redisUrl = process.argv[3];
var db = earls.getRedis(redisUrl);
var stats = new earls.Stats(db);
var rd = readline.createInterface({
input: fs.createReadStream(filename),
output: process.stdout,
terminal: false
});
var count = 0;
rd.on('line', function(line) {
var tweet = JSON.parse(line);
console.log(tweet.id_str);
stats.checkTweet(tweet);
count += 1;
});
rd.on('close', function() {
console.log("queued " + count + " tweets for processing");
stats.queue.drain = function() {
console.log("finished processing tweets");
process.exit(0);
};
});