<commit_before>var restify = require( 'restify' );
var bindIp = '0.0.0.0', bindPort = '8080';
var quotes = require('./model.js').model;
var crypto = require('crypto');
var ua = require('universal-analytics');
var visitor = ua('UA-2158627-15');
var fs = require('fs');
var testNLP = false;

var og = []; var oga = []; var ogt = [];
var bg = []; var bga = []; var bgt = [];

var server = restify.createServer( {

    name: 'howmuchisthe.fish',
    handleUpgrades: true

} );

server.use( restify.queryParser() );
server.use( restify.bodyParser() );
server.use( restify.CORS() );
server.use(restify.jsonp());
server.use(restify.gzipResponse());
server.use(restify.throttle({
  burst: 50,
  rate: 30,
  ip: true
  }
));

server.get( {path: '/json'}, noRequest );
server.get( {path: '/json/random'}, randomQuote );
server.get( {path: '/json/random/generate'}, generateQuote );
server.get( {path: '/json/random/video'}, randomVideo );
server.get( {path: '/json/daily'}, dailyQuote );
server.get( {path: '/json/perma/:quoteId'}, fixedQuote );

server.get(/.*/, restify.serveStatic({

    'directory': 'htdocs',
    'default': 'index.html'

}));

server.pre(restify.pre.userAgentConnection());

server.listen( bindPort, bindIp, function() {

    console.log( '%s listening at %s ', server.name , server.url );
    console.log( '#Quotes %s', quotes.length );
    console.log( 'Generating data for generation callback' );

    annotateModel();
    setupNLP();

    console.log( 'Ready.' );

});

function randomQuote( req, res, next ) {

    res.setHeader('Access-Control-Allow-Origin','*');

    var index = Math.floor(Math.random() * (quotes.length)) ;

    visitor.pageview("/json/quote/" + index).send();
    visitor.event("Return Quote", "Random Quote").send()

    res.json( 200, getQuote(index) );
    return next();

}

function randomVideo( req, res, next ) {

    res.setHeader('Access-Control-Allow-Origin','*');

    var theObject = {
        "quote": {
            "videos": []
        }
    };

    var index;
    var theQuote;

    while(theObject.quote.videos.length < 1) {
        index = Math.floor(Math.random() * (quotes.length)) ;
        theQuote = getQuote(index);

        if (theQuote.quote.videos && theQuote.quote.videos.length > 0) {
            theObject.quote.videos.push(theQuote.quote.videos[Math.floor(Math.random() * (heQuote.quote.videos.length))]);
        }
    }

    visitor.pageview("/json/random/video/" + index).send();
    visitor.event("Return Video", "Random Video").send()

    res.json( 200, theObject );
    return next();<commit_msg>Add video<commit_after>var restify = require( 'restify' );
var bindIp = '0.0.0.0', bindPort = '8080';
var quotes = require('./model.js').model;
var crypto = require('crypto');
var ua = require('universal-analytics');
var visitor = ua('UA-2158627-15');
var fs = require('fs');
var testNLP = false;

var og = []; var oga = []; var ogt = [];
var bg = []; var bga = []; var bgt = [];

var server = restify.createServer( {

    name: 'howmuchisthe.fish',
    handleUpgrades: true

} );

server.use( restify.queryParser() );
server.use( restify.bodyParser() );
server.use( restify.CORS() );
server.use(restify.jsonp());
server.use(restify.gzipResponse());
server.use(restify.throttle({
  burst: 50,
  rate: 30,
  ip: true
  }
));

server.get( {path: '/json'}, noRequest );
server.get( {path: '/json/random'}, randomQuote );
server.get( {path: '/json/random/generate'}, generateQuote );
server.get( {path: '/json/random/video'}, randomVideo );
server.get( {path: '/json/daily'}, dailyQuote );
server.get( {path: '/json/perma/:quoteId'}, fixedQuote );

server.get(/.*/, restify.serveStatic({

    'directory': 'htdocs',
    'default': 'index.html'

}));

server.pre(restify.pre.userAgentConnection());

server.listen( bindPort, bindIp, function() {

    console.log( '%s listening at %s ', server.name , server.url );
    console.log( '#Quotes %s', quotes.length );
    console.log( 'Generating data for generation callback' );

    annotateModel();
    setupNLP();

    console.log( 'Ready.' );

});

function randomQuote( req, res, next ) {

    res.setHeader('Access-Control-Allow-Origin','*');

    var index = Math.floor(Math.random() * (quotes.length)) ;

    visitor.pageview("/json/quote/" + index).send();
    visitor.event("Return Quote", "Random Quote").send()

    res.json( 200, getQuote(index) );
    return next();

}

function randomVideo( req, res, next ) {

    res.setHeader('Access-Control-Allow-Origin','*');

    var theObject = {
        "quote": {
            "videos": []
        }
    };

    var index;
    var theQuote;

    while(theObject.quote.videos.length < 1) {
        index = Math.floor(Math.random() * (quotes.length)) ;
        theQuote = getQuote(index);

        if (theQuote.quote.videos && theQuote.quote.videos.length > 0) {
            theObject.quote.videos.push(theQuote.quote.videos[Math.floor(Math.random() * (theQuote.quote.videos.length))]);
        }
    }

    visitor.pageview("/json/random/video/" + index).send();
    visitor.event("Return Video", "Random Video").send()

    res.json( 200, theObject );
    return next();
{'fraction_non_alphanumeric': 0.19256953900019452, 'fraction_numerical': 0.011281851779809376, 'mean_word_length': 3.432758620689655, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1278675', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1713, 'n_words': 352}