<commit_before>'use strict';

const Promise = require('bluebird');
const _ = require('underscore');
const fs = Promise.promisifyAll(require('fs'));
const Scraper = require('images-scraper');
const google = new Scraper.Google();
const bing = new Scraper.Bing();
const yahoo = new Scraper.Yahoo();
const picsearch = new Scraper.Picsearch();

//photo only
//google: &tbs=itp:photo
//bing: &qft=+filterui:photo-photo

// google.list({
//   keyword: 'banana',
//   num: 10,
//   detail: true,
//   nightmare: {
//     show: true
//   }
// })
// .then(function (res) {
//   console.log('first 10 results from google', res);
// }).catch(function(err) {
//   console.log('err', err);
// });
 
// // you can also watch on events 
// google.on('result', function (item) {
//   console.log('out', item);
// });

function normalizeBingToGoogle(imgObjSet) {
  return _.map(imgObjSet, (item) => {
    let imgObj = item;
    imgObj.thumbnail_url = imgObj.thumb;
    delete imgObj.thumb;
    imgObj.size = `${imgObj.size.slice(0, -2)}000`;
    imgObj.type = `image/${imgObj.format}`;
    return imgObj;
  });
}

function searchBing(queryString, maxResultsNum) {
  bing.list({
    keyword: queryString,
    num: maxResultsNum,
    detail: true
  })
  .then(res => {
    const normalRes = normalizeBingToGoogle(res);
    writeFile(`./results/${queryString.replace(' ', '_')}.js`, normalRes);
    writeFile(`./results/${queryString.replace(' ', '_')}.json`, normalRes);
  }).catch(err => {
    throw err;
  });
}

module.exports = {
  searchBing: searchBing,
};<commit_msg>Modify legacy code<commit_after>'use strict';

const Promise = require('bluebird');
// const _ = require('underscore');
// const fs = Promise.promisifyAll(require('fs'));
const Scraper = require('images-scraper');
const google = new Scraper.Google();
const bing = new Scraper.Bing();
// const yahoo = new Scraper.Yahoo();
// const picsearch = new Scraper.Picsearch();

// photo only
// google: &tbs=itp:photo
// bing: &qft=+filterui:photo-photo

function searchGoogle(queryString, maxResultsNum) {
  return google.list({
    keyword: queryString,
    num: maxResultsNum,
    detail: true,
    nightmare: {
      show: false
    }
  });
  // // you can also watch on events
  // google.on('result', function (item) {
  //   console.log('out', item);
  // });
}

function normalizeBingToGoogle(imgObjSet) {
  return imgObjSet.map(item => {
    let imgObj = item;
    imgObj.thumbnail_url = imgObj.thumb;
    delete imgObj.thumb;
    imgObj.size = `${imgObj.size.slice(0, -2)}000`;
    imgObj.type = `image/${imgObj.format}`;
    return imgObj;
  });
}

function searchBing(queryString, maxResultsNum) {
  return new Promise((resolve, reject) => {
    bing.list({
      keyword: queryString,
      num: maxResultsNum,
      detail: true
    })
    .then(res => {
      resolve(normalizeBingToGoogle(res));
      // writeFile(`./results/${queryString.replace(' ', '_')}.js`, normalRes);
      // writeFile(`./results/${queryString.replace(' ', '_')}.json`, normalRes);
    })
    .catch(err => {
      reject(err);
    });
  });
}


module.exports = {
  searchGoogle: searchGoogle,
  searchBing: searchBing,
};
{'fraction_non_alphanumeric': 0.18259493670886076, 'fraction_numerical': 0.004430379746835443, 'mean_word_length': 3.366022099447514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '4813562', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1081, 'n_words': 221}