<commit_before>const cheerio = require('cheerio');
const request = require('request');
const moment = require('moment');

var nameRegex = /\s-\s.*/;
var instrRegex = /Instructor:\s+/;
var updateRegex = /Last\sUpdate:\s+/;
var htmlRegex = /index\.html/;

var Course = function (url, secret) {
  this.url = url;
  this.secret = secret;
}

Course.prototype.scrapeInfo = function () {
  var course = this;
  return new Promise(function(resolve, reject) {
    request(course.url, function (error, response, body) {
      if (!error) {
        var $ = cheerio.load(body);
        course.name = $('font').eq(0).text().replace(nameRegex, '');
        course.instructor = $('font').eq(1).text().replace(instrRegex, '');
        course.last_update = moment($('font').eq(4).text().replace(updateRegex, ''), 'M/D/YYYY h:mm:ss A').toString();
        resolve(course);
      } else {
        reject(error);
      }
    });
  });
};

Course.prototype.scrapeScore = function () {
  var course = this;
  var url = course.url.replace(htmlRegex, 'coursestand.html');
  return new Promise(function(resolve, reject) {
    request(url, function (error, response, body) {
      if (!error) {
        var $ = cheerio.load(body);
        var tables = $('table');
        var table;
        tables.each(function () {
          if ($(this).attr('cellpadding') == 3) {
            table = $(this);
          }
        })
        // scrape categories info from the first three rows
        var row = table.children().first();
        var numCategories = row.children().length - 3;

        var categories = [];

        var item = row.children().first().next().next(); // first category
        var prop = row.next().children().first().next().next(); // first prop of first category
        var value = row.next().next().children().first().next().next(); // first value of first prop
        for (var i = 0; i < numCategories; i++) {
          var newCategory = {};
          newCategory.name = item.text();
          newCategory.props = [];
          for (var j = 0; j < item.attr('colspan'); j++) {
            if (value.text().trim().length > 0) {
              newCategory.props.push({
                name: prop.text(),
                value: value.text()
              });
            } else {
              newCategory.props.push({
                name: prop.text()
              });
            }
            prop = prop.next();
            value = value.next();
          }
          categories.push(newCategory);
          item = item.next();
        }

        for (var i = 0; i < table.children().length; i++) {
          if (row.children().first().text() == course.secret) {
            break;
          }
          row = row.next();
        }
        course.categories = categories;
        course.numCategories = numCategories;
        course.overallRank = parseInt(row.children().last().prev().text());
        course.overallScore = row.children().last().text();
        resolve(course);
      } else {
        reject(error);
      }
    });
  });
};
<commit_msg>Remove unnecessary numCategories in return val<commit_after>const cheerio = require('cheerio');
const request = require('request');
const moment = require('moment');

var nameRegex = /\s-\s.*/;
var instrRegex = /Instructor:\s+/;
var updateRegex = /Last\sUpdate:\s+/;
var htmlRegex = /index\.html/;

var Course = function (url, secret) {
  this.url = url;
  this.secret = secret;
}

Course.prototype.scrapeInfo = function () {
  var course = this;
  return new Promise(function(resolve, reject) {
    request(course.url, function (error, response, body) {
      if (!error) {
        var $ = cheerio.load(body);
        course.name = $('font').eq(0).text().replace(nameRegex, '');
        course.instructor = $('font').eq(1).text().replace(instrRegex, '');
        course.last_update = moment($('font').eq(4).text().replace(updateRegex, ''), 'M/D/YYYY h:mm:ss A').toString();
        resolve(course);
      } else {
        reject(error);
      }
    });
  });
};

Course.prototype.scrapeScore = function () {
  var course = this;
  var url = course.url.replace(htmlRegex, 'coursestand.html');
  return new Promise(function(resolve, reject) {
    request(url, function (error, response, body) {
      if (!error) {
        var $ = cheerio.load(body);
        var tables = $('table');
        var table;
        tables.each(function () {
          if ($(this).attr('cellpadding') == 3) {
            table = $(this);
          }
        })
        // scrape categories info from the first three rows
        var row = table.children().first();
        var numCategories = row.children().length - 3;

        var categories = [];

        var item = row.children().first().next().next(); // first category
        var prop = row.next().children().first().next().next(); // first prop of first category
        var value = row.next().next().children().first().next().next(); // first value of first prop
        for (var i = 0; i < numCategories; i++) {
          var newCategory = {};
          newCategory.name = item.text();
          newCategory.props = [];
          for (var j = 0; j < item.attr('colspan'); j++) {
            if (value.text().trim().length > 0) {
              newCategory.props.push({
                name: prop.text(),
                value: value.text()
              });
            } else {
              newCategory.props.push({
                name: prop.text()
              });
            }
            prop = prop.next();
            value = value.next();
          }
          categories.push(newCategory);
          item = item.next();
        }

        for (var i = 0; i < table.children().length; i++) {
          if (row.children().first().text() == course.secret) {
            break;
          }
          row = row.next();
        }
        course.categories = categories;
        course.overallRank = parseInt(row.children().last().prev().text());
        course.overallScore = row.children().last().text();
        resolve(course);
      } else {
        reject(error);
      }
    });
  });
};

{'fraction_non_alphanumeric': 0.17134877608017085, 'fraction_numerical': 0.002957121734844751, 'mean_word_length': 2.0049358341559724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1299153', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1714, 'n_words': 389}