<commit_before>var Snoocore = require('snoocore');
var config = require('../config/config.json');
var TitleFormatPass = require('./passes/TitleFormatPass');
var logger = require('./Logger');

var reddit = new Snoocore({
    userAgent: 'UltraHardcore Flair Checker',
    throttle: 1000,
    oauth: config.login.oauth,
    login: config.login.account
});

var formatPass = new TitleFormatPass(reddit);

logger.info('Starting up database');
require('./db/DbInit')().then(function() {
    return formatPass.removeOld()
}).then(function() {
    logger.info('Authenticating with Reddit');
    return reddit.auth()
}).then(function() {
    logger.info('Fetching reddit posts');
    return reddit('/r/$subreddit/search').get(config.titlePass.query);
}).then(function(results) {
    logger.info('Found %d posts to check', results.data.children.length);
    logger.info('Starting title format check');
    return formatPass.checkPosts(results.data.children);
}).catch(function(err) {
    logger.error('Uncaught error during script: %s', err);
});<commit_msg>refactor(index): move annonymous functions into proper functions<commit_after>var Snoocore = require('snoocore');
var config = require('../config/config.json');
var TitleFormatPass = require('./passes/TitleFormatPass');
var logger = require('./Logger');
var Q = require('q');

var reddit = new Snoocore({
    userAgent: 'UltraHardcore Flair Checker',
    throttle: 1000,
    oauth: config.login.oauth,
    login: config.login.account
});

var formatPass = new TitleFormatPass(reddit);

initDatabase()
    .then(authenticate)
    .then(titlePass)
    .catch(function(err) {
        logger.error('Uncaught error during scripts: %s', err);
    });

/**
 * Pass that works once for each post to check titles. Skips any previously parsed posts
 *
 * @returns {Q.promise}
 */
function titlePass() {
    logger.info('Starting title based pass');
    return reddit('/r/$subreddit/search').get(config.titlePass.query).then(function(results) {
        logger.info('Found %d posts to check', results.data.children.length);

        logger.info('Starting title format check');
        return formatPass.checkPosts(results.data.children);
    });
}

/**
 * Authenticate the account with reddit OAuth
 *
 * @returns {Q.promise}
 */
function authenticate() {
    logger.info('Authenticating with Reddit');

    return reddit.auth();
}

/**
 * Sets up the database and syncs models structure and then removes all the expired post checks from the database
 *
 * @returns {Q.promise}
 */
function initDatabase() {
    logger.info('Starting up database');

    return require('./db/DbInit')()
        .then(formatPass.removeOld)
}
{'fraction_non_alphanumeric': 0.14930424971793907, 'fraction_numerical': 0.003008649868371568, 'mean_word_length': 4.185185185185185, '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': '1010501', 'n_tokens_mistral': 800, 'n_tokens_neox': 789, 'n_words': 198}