<commit_before>/* jshint esnext: true */

// WebApp
// ======
// An express server using jade, static files and a repl

// Modules
// =======
var http = require( 'http' );
var fs = require( 'fs' );
var path = require( 'path' );
var express = require( 'express' );
var serveStatic = require( 'serve-static' );
var W = require( 'w-js' );
var less = require( 'less' );
var repl = require( 'repl' );
var request = require( 'request' );
var cheerio = require( 'cheerio' );

// Make & Init
// ===========

function makeWebApp () {
    return {
        port: process.env.PORT || 9999,
        isLocal: W.isDefined( process.env.IS_LOCAL ) ? Boolean( process.env.IS_LOCAL ) : false,
        fetchFromSymphonyEvery: 3000,
        symphonyUrl: process.env.SYMPHONY_URL || (function () { throw new Error( 'No SYMPHONY_URL env set' ); }())
    };
}

var initWebApp = W.composePromisers( fetchSymphony,
                                     startAutoFetchSymphony,
                                     makeExpressApp,
                                     makeServer,
                                     makeRepl,
                                     W.makeReporter( 'OK', 'Server running.' ) );

initWebApp( makeWebApp() )
    .success( function ( app ) {
        W.report( 'OK', 'Listening on port:', app.port );
    })
    .error( function ( err ) {
        W.report( 'Error', 'Failed to create app' );
        throw err;
    });

// Promisers
// =========

function fetchSymphony ( app ) {
    return W.promise( function ( resolve, reject ) {
        getDataFromSymphony( app )
            .error( function ( err ) {
                W.report( 'ERROR', 'Failed to load symphony' );
                reject( err );
            })
            .success( function ( data ) {
                app.symphony = cheerio.load( data, { xmlMode: true } );
                resolve( app );
            });
    });    
}

function startAutoFetchSymphony ( app ) {
    return W.promise( function ( resolve, reject ) {
        (function recur () {
            getDataFromSymphony( app )
                .success( function ( data ) {
                    app.symphony = cheerio.load( data );
                    setTimeout( recur, app.fetchFromSymphonyEvery );
                })
                .error( function ( err ) {
                    console.error( 'Failed to fetch from symphony', err );
                });
        }());
        resolve( app );
    });
}

function makeExpressApp ( app ) {
    return W.promise( function ( resolve, reject ) {

        app.expressApp = express();

        // Jade
        // ----
        app.expressApp.set( 'view engine', 'jade' );
        app.expressApp.set( 'views', path.join( __dirname, 'views' ) );
        if ( true ) { app.expressApp.locals.pretty = true; }
<commit_msg>Fixed symphony fetch<commit_after>/* jshint esnext: true */

// WebApp
// ======
// An express server using jade, static files and a repl

// Modules
// =======
var http = require( 'http' );
var fs = require( 'fs' );
var path = require( 'path' );
var express = require( 'express' );
var serveStatic = require( 'serve-static' );
var W = require( 'w-js' );
var less = require( 'less' );
var repl = require( 'repl' );
var request = require( 'request' );
var cheerio = require( 'cheerio' );

// Make & Init
// ===========

function makeWebApp () {
    return {
        port: process.env.PORT || 9999,
        isLocal: W.isDefined( process.env.IS_LOCAL ) ? Boolean( process.env.IS_LOCAL ) : false,
        fetchFromSymphonyEvery: 3000,
        symphonyUrl: process.env.SYMPHONY_URL || (function () { throw new Error( 'No SYMPHONY_URL env set' ); }())
    };
}

var initWebApp = W.composePromisers( fetchSymphony,
                                     startAutoFetchSymphony,
                                     makeExpressApp,
                                     makeServer,
                                     makeRepl,
                                     W.makeReporter( 'OK', 'Server running.' ) );

initWebApp( makeWebApp() )
    .success( function ( app ) {
        W.report( 'OK', 'Listening on port:', app.port );
    })
    .error( function ( err ) {
        W.report( 'Error', 'Failed to create app' );
        throw err;
    });

// Promisers
// =========

function fetchSymphony ( app ) {
    return W.promise( function ( resolve, reject ) {
        getDataFromSymphony( app )
            .error( function ( err ) {
                W.report( 'ERROR', 'Failed to load symphony' );
                reject( err );
            })
            .success( function ( data ) {
                app.symphony = cheerio.load( data, { xmlMode: true } );
                resolve( app );
            });
    });    
}

function startAutoFetchSymphony ( app ) {
    return W.promise( function ( resolve, reject ) {
        (function recur () {
            getDataFromSymphony( app )
                .success( function ( data ) {
                    app.symphony = cheerio.load( data );
                    setTimeout( recur, app.fetchFromSymphonyEvery );
                })
                .error( function ( err ) {
                    console.error( 'Failed to fetch from symphony', err );
                    setTimeout( recur, app.fetchFromSymphonyEvery );
                });
        }());
        resolve( app );
    });
}

function makeExpressApp ( app ) {
    return W.promise( function ( resolve, reject ) {

        app.expressApp = express();

        // Jade
        // ----
        app.expressApp.set( 'view engine', 'jade' );
        app.expressApp.set( 'views', path.join( __dirname, 'views' ) );
        if ( true ) { app.expressApp.locals.pretty = true; }

{'fraction_non_alphanumeric': 0.14202334630350194, 'fraction_numerical': 0.002829854969932791, 'mean_word_length': 1.6954242135367017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '771275', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1592, 'n_words': 415}