<commit_before>var express = require('express');
var app = express();

var cors = require('cors');
app.use(cors());

var mongoose = require('mongoose');
mongoose.connect('mongodb://'+process.env.IP+':27017/neobadges');
require('./models/site');

var stats = require('./modules/stats');
var badges = require('./modules/badges');
require('./modules/discord');

var _log = console.log;
console.log = function(msg) {
	_log('['+new Date(new Date().getTime()+1000*60*60).toLocaleTimeString({},{hour12:false})+'] '+msg);
}

app.get('/site/:site', function(req, res) {
	var currentTime = new Date().getTime();
	
	var site = req.params.site;
	console.log('Getting stats for '+site+'...');
		
	stats.get(site, function(statObject) {
		badges.add(statObject, site, function(data) {
			console.log('Finished in '+(new Date().getTime()-currentTime)+'ms!');
			res.json(data);
		});
	});
});<commit_msg>Added check to see if user exists before adding badges<commit_after>var express = require('express');
var app = express();

var cors = require('cors');
app.use(cors());

var mongoose = require('mongoose');
mongoose.connect('mongodb://'+process.env.IP+':27017/neobadges');
require('./models/site');

var stats = require('./modules/stats');
var badges = require('./modules/badges');
require('./modules/discord');

var _log = console.log;
console.log = function(msg) {
	_log('['+new Date(new Date().getTime()+1000*60*60).toLocaleTimeString({},{hour12:false})+'] '+msg);
}

app.get('/site/:site', function(req, res) {
	var currentTime = new Date().getTime();
	
	var site = req.params.site;
	console.log('Getting stats for '+site+'...');
		
	stats.get(site, function(statObject) {
		if (statObject) {
			badges.add(statObject, site, function(data) {
				console.log('Finished in '+(new Date().getTime()-currentTime)+'ms!');
				res.json(data);
			});
		}
		else {
			res.send('notfound');
		}
	});
});
{'fraction_non_alphanumeric': 0.22175066312997346, 'fraction_numerical': 0.015915119363395226, 'mean_word_length': 5.123376623376624, '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': '2908019', 'n_tokens_mistral': 698, 'n_tokens_neox': 649, 'n_words': 123}