Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bugfixes + examples

  • Loading branch information...
commit 3e65b7848ba15a77feb4fbaeb983b54dcf97115d 1 parent b879b56
@dmongeau dmongeau authored
View
1  .npmignore
@@ -1,2 +1,3 @@
intermediate/
publish/
+**/config.js
View
19 README.md
@@ -1,4 +1,4 @@
-Twitter-processing
+twitter-processor
===========
Receive Tweets from the Twitter Streaming API and process them using custom processors.
@@ -6,25 +6,20 @@ Receive Tweets from the Twitter Streaming API and process them using custom proc
Installation
---------------
- npm install twitter-processing
+ npm install twitter-processor
Usage
---------------
- var twitterProcessing = require('twitter-processing');
+ var twitterProcessor = require('twitter-processor');
- var processing = twitterProcessing({
+ var processor = twitterProcessor.createProcessor({
'debug' : true,
- 'processor' : function(job,done) {
- job.data.addedKey = 'value';
+ 'processor' : function(tweet,done) {
+ tweet.addedKey = 'value';
done();
},
- 'redis' : {
- 'host' : 'localhost',
- 'post' : 6379,
- 'password' : ''
- },
'twitter' : {
'consumer_key' : '',
'consumer_secret' : '',
@@ -36,6 +31,6 @@ Usage
}
});
- processing.on('data',function(tweet) {
+ processor.on('data',function(tweet) {
console.log(tweet.addedKey); //value
});
View
12 examples/config.sample.js
@@ -0,0 +1,12 @@
+var CONFIG = {
+
+ 'twitter' : {
+ 'consumer_key' : '',
+ 'consumer_secret' : '',
+ 'access_token_key' : '',
+ 'access_token_secret' : ''
+ }
+
+};
+
+module.exports = exports = CONFIG;
View
20 examples/filter.js
@@ -4,16 +4,24 @@ var CONFIG = require('./config');
var processor = twitterProcessor.createProcessor({
'debug' : true,
- 'processor' : function(job,done) {
- job.data.addedKey = 'value';
- done();
+ 'processor' : function(tweet,done) {
+ tweet.addedKey = 'value';
+ setTimeout(function() {
+ done();
+ },Math.round(Math.random()*3000));
},
'twitter' : CONFIG.twitter,
'filter' : {
- 'track' : 'Twitter'
+ 'track' : 'Bieber'
}
});
+processor.on('add', function(tweet) {
+ //console.log('Tweet added',tweet.text);
+});
+
processor.on('tweet', function(tweet) {
- console.log('Tweet',tweet.text);
-});
+ console.log('Tweet processed',tweet.text);
+});
+
+processor.start();
View
19 lib/processor.js
@@ -16,7 +16,7 @@ var TwitterProcessor = function(options) {
//Options
this.options = utils.merge({
'debug' : false,
- 'processor' : function(job,done){
+ 'processor' : function(tweet,done){
done();
},
'twitter' : {
@@ -64,13 +64,16 @@ TwitterProcessor.prototype.init = function() {
var self = this;
- this.twit = new twitter(this.options.twitter);
+ this.twitter = new twitter(this.options.twitter);
//Create queue
this.queue = queueleuleu.createQueue({
+ 'debug' : this.options.debug,
'autostart' : true,
'processor' : function(job,done) {
- self.process.call(self,job,done);
+ self.process.call(self,job,function() {
+ done();
+ });
}
});
@@ -103,8 +106,10 @@ TwitterProcessor.prototype._startStream = function() {
//Filter tweet text to remove symbols
tweet.textFiltered = utils.filterTweetText(tweet.text);
- //Create the job
- self.jobs.add(tweet);
+ //Add tweet to queue
+ self.queue.add(tweet);
+
+ self.emit('add',tweet);
});
@@ -180,8 +185,8 @@ TwitterProcessor.prototype.process = function(job,done) {
if(!this.processor) done();
if(this.processor) {
- this.processor(job,function() {
- job.save(done);
+ this.processor(job.data,function() {
+ done();
});
}
View
2  package.json
@@ -6,7 +6,7 @@
"maintainers": [
"David Mongeau-Petitpas <dmp@atelierfolklore.ca>"
],
- "version": "0.0.7",
+ "version": "0.0.8",
"dependencies": {
"ntwitter" : "0.5.x",
"queueleuleu" : "0.x"
Please sign in to comment.
Something went wrong with that request. Please try again.