I want to update a Twit stream.
I have a Twitter stream made with the twpm Twpm module (you can find it here: https://github.com/ttezel/twit ).
Here is my code:
Researches.find().observeChanges({
added: function(){
hashArray = Researches.find().fetch();
hashCount = Researches.find().count();
for(i=0; i<hashCount; i++){
hashArray[i]= hashArray[i].hashtag;
}
}
});
stream = T.stream('statuses/filter', {track: hashArray});
stream.on('tweet', Meteor.bindEnvironment(function(tweet) {
tweetText = tweet.text;
tweetText = tweetText.toLowerCase();
for(i=0; i<hashCount; i++){
var hashCompare = hashArray[i];
hashCompare = hashCompare.toLowerCase();
var isInString = tweetText.search(hashCompare);
if(isInString>=0)
goodHash = hashArray[i];
}
tweetToInsert = {
user: tweet.user.screen_name,
tweet: tweet.text,
picture: tweet.user.profile_image_url,
date: new Date().getTime(),
hashtag: goodHash
};
matchTweet = Tweets.findOne({tweet:tweetToInsert.tweet});
if(matchTweet || (lastTweet.user == tweetToInsert.user) || (lastTweet.tweet == tweetToInsert.tweet)){
} else {
console.log(tweetToInsert.tweet);
Tweets.insert(tweetToInsert, function(error) {
if(error)
console.log(error);
});
}
lastTweet = {
user: tweetToInsert.user,
tweet: tweetToInsert.tweet
}
nbTweet = Tweets.find({hashtag: goodHash}).count();
tweetToDelete = nbTweet-25;
if(nbTweet>25){
for(i=0; i<tweetToDelete;i++){
idDelete = Tweets.findOne({hashtag: goodHash});
Tweets.remove(idDelete._id);
}
}
}));
As you can see, I have an observation in my research collection with which I created an array with all the hashtag. Then I made my stream using this array to track all these hashtags.
Now here is my problem. When I had a new hashtag of my collection, my array updated itself with a new hashtag and that’s good. The problem is that the thread is not updating itself.
What i tried
I tried using the .stop () stream provided by the Twit documentation (this works great), but when I tried to restart it using .start (), it did not work.
, :
Researches.find().observeChanges({
added: function(){
hashArray = Researches.find().fetch();
hashCount = Researches.find().count();
for(i=0; i<hashCount; i++){
hashArray[i]= hashArray[i].hashtag;
}
if(stream){
stream.stop();
stream.start();
}
}
});
, , / Twit , , .