<commit_before>var twitter = require('ntwitter');
var current = {text:'Australia'};
var Tweet = require('../models').Tweet;
var countries = require('../models').Countries;

module.exports = function(app, config, io) {
	var twit = new twitter(config.twitter);

	twit.stream('statuses/filter', {track:config.hashtag}, function( stream) {
		stream.on('data', function (data) {
			var country = getCountryForText(data.text);
			var tweet = new Tweet({tweet:data, country:country}); 
			tweet.save();
			
			if(!country) {
				respondToError(data);
				return;
			}

			
			current = data;		
	   		io.sockets.emit('update', tweet);	 
	  	});
	});
}

function respondToError(data) {
  // Let tweeter know that country did not validate
  console.log('respond to error')
}

// private helper to validate tweet text if country is available<commit_msg>Fixed Heroku CEDAR issue not supporting WebSockets. It now uses xhr polling<commit_after>var twitter = require('ntwitter');
var current = {text:'Australia'};
var Tweet = require('../models').Tweet;
var countries = require('../models').Countries;

module.exports = function(app, config, io) {
	var twit = new twitter(config.twitter);

	//Heroku "doesn't support" websockets on the Cedar stack yet (no word on when they will). 
	//They recommend adding the following code to your Socket.io implementation:
	io.configure(function () { 
	  io.set("transports", ["xhr-polling"]); 
	  io.set("polling duration", 10); 
	});
	
	twit.stream('statuses/filter', {track:config.hashtag}, function( stream) {
		stream.on('data', function (data) {
			var country = getCountryForText(data.text);
			var tweet = new Tweet({tweet:data, country:country}); 
			tweet.save();
			
			if(!country) {
				respondToError(data);
				return;
			}

			
			current = data;		
	   		io.sockets.emit('update', tweet);	 
	  	});
	});
}

function respondToError(data) {
  // Let tweeter know that country did not validate
  console.log('respond to error')
}

// private helper to validate tweet text if country is available
{'fraction_non_alphanumeric': 0.1447562776957164, 'fraction_numerical': 0.0009847365829640572, 'mean_word_length': 3.8729016786570742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3927080', 'n_tokens_mistral': 715, 'n_tokens_neox': 626, 'n_words': 173}