<commit_before>// Invoke 'strict' JavaScript mode
'use strict';

var mongoose = require('mongoose');
var Counter = require('../models/counters.js');
var request = require('request');

var database = require('../config/db');

var Video = require('../models/video.js');
var BannedVideo = require('../models/bannedvideo.js');
var api = require('../controllers/api.js');

mongoose.connect(database.url);

//Removes any videos that are either in the banned video list, or bans them if they're inaccessable.
exports.pruneVideoDatabase = function()
{
  Video.find({}, function(err, docs)
  {
    docs.forEach(function(doc)
    {
      // XXX TODO set this key in the 'config' directory
      var youtubeAPIKey = '<KEY>';
      request('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=' + doc.vidID + '&key=' + youtubeAPIKey, function (error, response, body)
      {
        if (!error && response.statusCode == 200)
        {
          var reqJSON = JSON.parse(body);
          for(var i = 0; i < reqJSON.data.children.length; i++)
          {
            console.log(reqJSON.data.children[i].data);
          }
        }
      });
    });
  });
};

exports.pruneVideoDatabase();

// Run this function Hourly
//schedule.scheduleJob('0 0 * * *', exports.pruneVideoDatabase);
<commit_msg>Pruner now scans JSON Data correctly per video, and has a delay to avoid overloading the youtube API<commit_after>// Invoke 'strict' JavaScript mode
'use strict';

var mongoose = require('mongoose');
var Counter = require('../models/counters.js');
var request = require('request');

var database = require('../config/db');

var Video = require('../models/video.js');
var BannedVideo = require('../models/bannedvideo.js');
var api = require('../controllers/api.js');

mongoose.connect(database.url);

//Removes any videos that are either in the banned video list, or bans them if they're inaccessable.
exports.pruneVideoDatabase = function()
{
  Video.find({}, function(err, docs)
  {
    var doc_count = 0;
    docs.forEach(function(doc)
    {
      doc_count++;
      // XXX TODO set this key in the 'config' directory
      var youtubeAPIKey = '<KEY>';
      var requestID = ('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=' + doc.videoID + '&key=' + youtubeAPIKey);
      //Short delay so we don't overuse the API
      setTimeout(request, 200 * doc_count, requestID, function (error, response, body)
      {
        if (!error && response.statusCode == 200)
        {
          var reqJSON = JSON.parse(body);
          console.log('This is the JSON data for ' + requestID + ':');
          console.log(reqJSON);
        }
      });
    });
  });
};

exports.pruneVideoDatabase();

// Run this function Hourly
//schedule.scheduleJob('0 0 * * *', exports.pruneVideoDatabase);

{'fraction_non_alphanumeric': 0.15470208183776024, 'fraction_numerical': 0.006101938262742283, 'mean_word_length': 3.128888888888889, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3585509', 'n_tokens_mistral': 875, 'n_tokens_neox': 839, 'n_words': 224}