<commit_before>var twitter = require('twitter');
var client = new twitter({
  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 fs = require('fs')
var utility = require('../api/helpers/utilities.js')

// checkDataType parses the tweet object to find any matching influencers, hashtags, or mentions and then returns an array of each found in the tweet
var checkDataType = function(tweet, trackers) {
  var mentions = tweet.entities.user_mentions;
  var hashtags = tweet.entities.hashtags;

  for(var i = 0; i < trackers.length; i++) {
    if(trackers[i].type === "influencer" && tweet.user.screen_name.toLowerCase() === trackers[i].name) {
        return {tweet: tweet, tracker: trackers[i]}
    } else if(trackers[i].type === "mention" && tweet.entities.user_mentions.length > 0 && !('retweet_status' in tweet)) {
        for(var j = 0; j < mentions.length; j++) {
            if(trackers[i].name === mentions[j].screen_name.toLowerCase()) {
                return {tweet: tweet, tracker: trackers[i]}
            }
        }
    } else if(trackers[i].type === "hashtag" && hashtags.length > 0 && !('retweet_status' in tweet)) {
        for(var j = 0; j < hashtags.length; j++) {
            if(trackers[i].name === hashtags[j].text.toLowerCase()) {
                return {tweet: tweet, tracker: trackers[i]}
            }
        }
    }

  }
  return false;
}

module.exports.twitterstream = function() {
    Tracker.find().populateAll().exec(function(err, trackers) {
        if(!err) {
            var track = {};

            trackers.forEach(function(t) {
                if(t.type == "influencer") {
                    if(track.follow) {
                      track.follow.push(t.twitter_id);
                    } else {
                      track.follow = [t.twitter_id];
                    }
                } else {
                    if(track.track) {
                      track.track.push(t.name);
                    } else {
                      track.track = [t.name];
                    }
                }
            }).join(',');

            client.stream('statuses/filter', track, function(stream) {
              stream.on('data', function(tweet) {
                console.log(tweet.text);
                var trackerData = checkDataType(tweet, trackers);
                console.log("Tracker Data:",trackerData !== null)
                if(trackerData) {
                    async.each(trackerData.tracker.twitter_accounts ,function(account, callback) {
                        Twitter_Account.findOne({id: account.id}).populate('user').exec(function(err, account) {
                            if(!err) {
                                console.log("sending email...",account)
                                callback(utility.sendEmail(account.user.email, "[TwitterMafiaApp] You have new updates!", trackerData, false));
                            } else {
                                callback(err)
                            }
                        });
                    });
                }
                console.log("*************************************\n\n");
              });

              stream.on('error', function(error) {
                console.log("ERROR!!",error)
                throw error;
              });
            });
        }
    });
}<commit_msg>Changed the track and follow values to be strings instead of arrays<commit_after>var twitter = require('twitter');
var client = new twitter({
  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 fs = require('fs')
var utility = require('../api/helpers/utilities.js')

// checkDataType parses the tweet object to find any matching influencers, hashtags, or mentions and then returns an array of each found in the tweet
var checkDataType = function(tweet, trackers) {
  var mentions = tweet.entities.user_mentions;
  var hashtags = tweet.entities.hashtags;

  for(var i = 0; i < trackers.length; i++) {
    if(trackers[i].type === "influencer" && tweet.user.screen_name.toLowerCase() === trackers[i].name) {
        return {tweet: tweet, tracker: trackers[i]}
    } else if(trackers[i].type === "mention" && tweet.entities.user_mentions.length > 0 && !('retweet_status' in tweet)) {
        for(var j = 0; j < mentions.length; j++) {
            if(trackers[i].name === mentions[j].screen_name.toLowerCase()) {
                return {tweet: tweet, tracker: trackers[i]}
            }
        }
    } else if(trackers[i].type === "hashtag" && hashtags.length > 0 && !('retweet_status' in tweet)) {
        for(var j = 0; j < hashtags.length; j++) {
            if(trackers[i].name === hashtags[j].text.toLowerCase()) {
                return {tweet: tweet, tracker: trackers[i]}
            }
        }
    }

  }
  return false;
}

module.exports.twitterstream = function() {
    Tracker.find().populateAll().exec(function(err, trackers) {
        if(!err) {
            var track = {};

            trackers.forEach(function(t) {
                if(t.type == "influencer") {
                    if(track.follow) {
                      track.follow += ',' + t.twitter_id;
                    } else {
                      track.follow = t.twitter_id.toString();
                    }
                } else {
                    if(track.track) {
                      track.track += ',' + t.name;
                    } else {
                      track.track = t.name;
                    }
                }
            });

            client.stream('statuses/filter', track, function(stream) {
              stream.on('data', function(tweet) {
                console.log(tweet.text);
                var trackerData = checkDataType(tweet, trackers);
                console.log("Tracker Data:",trackerData !== null)
                if(trackerData) {
                    async.each(trackerData.tracker.twitter_accounts ,function(account, callback) {
                        Twitter_Account.findOne({id: account.id}).populate('user').exec(function(err, account) {
                            if(!err) {
                                console.log("sending email...",account)
                                callback(utility.sendEmail(account.user.email, "[TwitterMafiaApp] You have new updates!", trackerData, false));
                            } else {
                                callback(err)
                            }
                        });
                    });
                }
                console.log("*************************************\n\n");
              });

              stream.on('error', function(error) {
                console.log("ERROR!!",error)
                throw error;
              });
            });
        }
    });
}
{'fraction_non_alphanumeric': 0.14099475697888622, 'fraction_numerical': 0.0014170327334561428, 'mean_word_length': 1.6918382913806256, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2607037', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1926, 'n_words': 362}