<commit_before>// server.js


// set up ========================
var express  = require('express');
var app      = express(); 								    // create our app w/ express
var mongoose = require('mongoose'); 					    // mongoose for mongodb
var port  	 = Number(process.env.PORT || 5000); 			// set the port
var crypto   = require('crypto');
var cron     = require('cron');
var morgan   = require('morgan'); 		              // log requests to the console (express4)
var bodyParser = require('body-parser');              // pull information from HTML POST (express4)
var methodOverride = require('method-override');      // simulate DELETE and PUT (express4)

var Client = require('node-rest-client').Client;      // node REST API client
client = new Client();

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
   service: "Gmail",
   auth: {
       user: ENV['EMAIL_USER'],
       pass: ENV['EMAIL_PASSWORD']
   }
});


// configuration =================
var database = require('./config/database');
mongoose.connect(database.url); 	// connect to mongoDB database on modulus.io

app.use(express.static(__dirname + '/public')); 				// set the static files location /public/img will be /img for users
app.use(morgan('dev')); 										            // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); 			      // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); 									                  // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());


// routes ======================================================================
require('./app/routes')(app);


// listen (start app with node server.js) ======================================
app.listen(port, function() {
  console.log("Listening on " + port);
});


// server logic ================================================================

// variables for regions and current game state
var currentState = {};
var regions = ['na','euw','eune','lan','las','br','tr','ru','oce'];

// cron job to check server status
var cronJob = cron.job("*/30 * * * * *", function(){

	var newState = {};

  // get each region's game status
	regions.forEach(function(region) {
		client.get("http://status.leagueoflegends.com/shards/" + region, function(data, response){
			newState[region] = data.services[1].status
			// send an email if the status has changed
			if (currentState[region]) {
				if (newState[region] != currentState[region]) {
					sendEmailAlert(region, newState[region]);
				};
			};
			currentState[region] = newState[region];
		});
	});

});
// run the cron job
cronJob.start();

// send alert emails if there is a status change
function sendEmailAlert(reg, newState){
	User.find({ region: reg }, function(err, docs) {
		console.log("Emailing users: " + docs);
		docs.forEach(function(user) {
			transporter.sendMail({
				from: "<EMAIL>", // sender address
				to: user.email, // comma separated list of receivers
				subject: user.region + " alert", // Subject line
				text: "The game server for " + user.region + " is now " + newState // plaintext body
			}, function(error, response){
				if(error){
					console.log(error);
				}else{
					console.log("Message sent: " + response.message);
				}
			});
		});
	});
};
<commit_msg>un-broke env vars<commit_after>// server.js


// set up ========================
var express  = require('express');
var app      = express(); 								    // create our app w/ express
var mongoose = require('mongoose'); 					    // mongoose for mongodb
var port  	 = Number(process.env.PORT || 5000); 			// set the port
var crypto   = require('crypto');
var cron     = require('cron');
var morgan   = require('morgan'); 		              // log requests to the console (express4)
var bodyParser = require('body-parser');              // pull information from HTML POST (express4)
var methodOverride = require('method-override');      // simulate DELETE and PUT (express4)

var Client = require('node-rest-client').Client;      // node REST API client
client = new Client();

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
   service: "Gmail",
   auth: {
       user: process.env.EMAIL_USER,
       pass: <PASSWORD>.EMAIL_PASSWORD
   }
});


// configuration =================
var database = require('./config/database');
mongoose.connect(database.url); 	// connect to mongoDB database on modulus.io

app.use(express.static(__dirname + '/public')); 				// set the static files location /public/img will be /img for users
app.use(morgan('dev')); 										            // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); 			      // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); 									                  // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());


// routes ======================================================================
require('./app/routes')(app);


// listen (start app with node server.js) ======================================
app.listen(port, function() {
  console.log("Listening on " + port);
});


// server logic ================================================================

// variables for regions and current game state
var currentState = {};
var regions = ['na','euw','eune','lan','las','br','tr','ru','oce'];

// cron job to check server status
var cronJob = cron.job("*/30 * * * * *", function(){

	var newState = {};

  // get each region's game status
	regions.forEach(function(region) {
		client.get("http://status.leagueoflegends.com/shards/" + region, function(data, response){
			newState[region] = data.services[1].status
			// send an email if the status has changed
			if (currentState[region]) {
				if (newState[region] != currentState[region]) {
					sendEmailAlert(region, newState[region]);
				};
			};
			currentState[region] = newState[region];
		});
	});

});
// run the cron job
cronJob.start();

// send alert emails if there is a status change
function sendEmailAlert(reg, newState){
	User.find({ region: reg }, function(err, docs) {
		console.log("Emailing users: " + docs);
		docs.forEach(function(user) {
			transporter.sendMail({
				from: "<EMAIL>", // sender address
				to: user.email, // comma separated list of receivers
				subject: user.region + " alert", // Subject line
				text: "The game server for " + user.region + " is now " + newState // plaintext body
			}, function(error, response){
				if(error){
					console.log(error);
				}else{
					console.log("Message sent: " + response.message);
				}
			});
		});
	});
};

{'fraction_non_alphanumeric': 0.21034025629695094, 'fraction_numerical': 0.0029459419649432907, 'mean_word_length': 3.423452768729642, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5338045', 'n_tokens_mistral': 2181, 'n_tokens_neox': 1912, 'n_words': 518}