<commit_before>var _ = require('lodash');
var cheerio = require('cheerio');
var moment = require('moment');
var debug = require('debug')('parser:postType');
var parse = require('./lib/parse');

function getPostType(snippet) {

    var $ = cheerio.load(snippet.html);

    if ($('.uiStreamSponsoredLink').length > 0) 
        var retVal = "promoted";
    else if ($('.uiStreamAdditionalLogging').length > 0)
        var retVal = "promoted";
    else
        var retVal = "feed";

    // TODO, don't use exclusion condition, but find a selector
    // for 'feed' too, and associate 'null' if nothing it is spot
    debug("・%s ∩ %s", snippet.id, retVal);
    return { 'postType': true, 
             'type': retVal };
};

var postType = {
    'name': 'postType',
    'requirements': {},
    'implementation': getPostType,
    'since': "2016-11-13",
    'until': moment().toISOString(),
};
<commit_msg>new approach to manage postType parsing<commit_after>var _ = require('lodash');
var cheerio = require('cheerio');
var moment = require('moment');
var debug = require('debug')('parser:postType');
var parse = require('./lib/parse');

function hasLike($) {
    var mayLike = $(".UFILikeLink");
    /* a number of entry for each like button present */
    // debug("Likes spot %d", mayLike.length);
    return (mayLike.length > 0 )
};

function getPostType(snippet) {

    debug("→ %j", _.omit(snippet, ['html']));

    var $ = cheerio.load(snippet.html);
    var retO = {
        'postType': false
    }

    /* new theory: is missing the timeStampContent and the <abbr>, so
     * the binary decision can start from that */

    if(!hasLike($)) {
        debug("Nope ・%s ", snippet.id);
        debugger;
        return retO;
    }

    // debug("<abbr>: %d", $("abbr").length);
    if($(".timestampContent").length === 0) {
        debug("Promoted ・%s ", snippet.id);
        retO.type = 'promoted';
        retO.postType = true;
    } else {
        debug("Feed ・%s ", snippet.id);
        retO.type = 'feed';
        retO.postType = true;
    }
    return retO;
};

var postType = {
    'name': 'postType',
    'requirements': {},
    'implementation': getPostType,
    'since': "2016-11-13",
    'until': moment().toISOString(),
};

{'fraction_non_alphanumeric': 0.1778673835125448, 'fraction_numerical': 0.008960573476702509, 'mean_word_length': 2.9038461538461537, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '7418832', 'n_tokens_mistral': 753, 'n_tokens_neox': 713, 'n_words': 185}