<commit_before>var basicScraper = require('../controllers/basicScraperController');
var getExternalUrl = require('../controllers/urlController').getExternalUrl;
var compare = require('../imgCompare').compare;
var CronJob = require('cron').CronJob;
var CronJobManager = require('cron-job-manager');
var nodemailer = require('nodemailer');
var ocr = require('../controllers/ocr');
var secret = require('../../config.js');
var Sequelize = require('sequelize');
var transporter = nodemailer.createTransport({
    service: 'mailgun',
    auth: secret.auth
});

module.exports = {

  getDate: function() {
    var date = new Date();
    var options = {
      year: "numeric", month: "2-digit",
      day: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit"
    };
    return date.toLocaleTimeString("en-us", options);
  },

  getNewCroppedImage: function(UserUrl, website, email, params, oldImg, cb) {
    basicScraper.getScreenshot(website, UserUrl.user_id, function(img1, email) {
      // crops new image so we can compare the the old cropped image
      basicScraper.cropImg(img1, params, true, function(newImg) {
        // checks for difference in pictures
        cb(oldImg, newImg)
      }); // basicScraper.cropImg(img1, params, true, function(img2) {
    }, email); // basicScraper.getScreenshot()
  },

  compareOCR: function(UserUrl, website, email, params, oldImg, cb) {
    // TODO: take values that are input to it, pass it through compare ocr functions? Should be in basicScroperController?
    this.getNewCroppedImage(UserUrl, website, email, params, oldImg, function(oldImg, newImg) {
      console.log('inside ocrCompare, oldImg', oldImg, 'newImg', newImg);
      /*
      have: /Users/banana/Projects/gitinit/loveBiscuits/server
      want: /Users/banana/Projects/gitinit/loveBiscuits/client/
      */

        newImg = __dirname.substr(0, __dirname.length - 12) + 'client/' + newImg;
        ocr.convertImageToText(newImg, function(err, text) {
          if (err) {
            console.log('ocr error' + err);
          } else {
            console.log('comparing text values');
            if (UserUrl.filter === 'greater') {
              console.log('TESTING greater')
              // pulls first set of numbers from text
              if (text.match(/\d+\.?\d*/gi)) {
                var compareVal = text.match(/\d+\.?\d*/gi)[0];
              }
              console.log('compareVal is', compareVal);
              if (compareVal < UserUrl.compareVal) {
                cb(oldImg, newImg);
              }
            } else if (UserUrl.filter == 'less') {
              console.log('TESTING less')
              // TODO: pull numeric value from text
              if (text.match(/\d+\.?\d*/gi)) {
                var compareVal = text.match(/\d+\.?\d*/gi)[0];
              }
              console.log('the compareVal is ', compareVal);
              if (compareVal > UserUrl.compareVal) {
                cb(oldImg, newImg);
              }
            } else if (UserUrl.filter == 'contains') {
              console.log('TESTING contains')
              // if a user wants to check for multiple words
              var contains = UserUrl.compareVal.split(',') || UserUrl.compareVal;
              // iterate through each word
              for (var i = 0; i < contains.length; i++) {
                // if text contains any of the values
                if (text.toLowerCase().indexOf(contains[i].toLowerCase()) > -1) {
                  cb(oldImg, newImg);
                } // if (text.indexOf(contains[i])) {
              } // for (var i = 0; i < contains.length; i++) {
            }  else {
              if (UserUrl.cronVal !== text) {
               cb(oldImg, newImg);
              } // if (UserUrl.cronVal !== text) {
            };
          }; // } else {
        }); // ocr.converImageToText(newImg, function(newImg) {
    }); //this.getNewCroppedImage(UserUrl, website, email, params, oldImg, function(oldImg, newImg) {
  },

  compareScreenShot: function(UserUrl, website, email, params, oldImg, cb) {
    this.getNewCroppedImage(UserUrl, website, email, params, oldImg, function(oldImg, newImg) {
      // checks for difference in pictures
      compare(oldImg, newImg, function (equal, oldImg, newImg){
        if (!equal){
          cb(oldImg, newImg);
        }; // if (!equal){
      }); // compare(img1, img2, function (equal){
    });
  },

  sendEmail: function(website, email, oldImg, newImg) {
    console.log('change detected on', website, 'sending email to ', email);
    // parameters for email

    // TODO: Add different mail options for different comparison funcitons.
    var mailOptions = {
        from: "The Blank Arrays <<EMAIL>@<EMAIL>>", // sender address
        to: email, // list of receivers
        subject: 'We found some tubular changes!', // Subject line
        text: 'Hi there! It looks like we found a change on '+ website + '!', // plaintext body
        html: "<span>The Scrapinit team found a change on " + website +"!</span>",
        attachments: [
        {
          path: oldImg
        },
        {
          path: newImg
        }
        ]
    };
<commit_msg>[Style] Added commas to last parameter in each column to abide to airbnb style guidelines<commit_after>var basicScraper = require('../controllers/basicScraperController');
var getExternalUrl = require('../controllers/urlController').getExternalUrl;
var compare = require('../imgCompare').compare;
var CronJob = require('cron').CronJob;
var CronJobManager = require('cron-job-manager');
var nodemailer = require('nodemailer');
var ocr = require('../controllers/ocr');
var secret = require('../../config.js');
var Sequelize = require('sequelize');
var transporter = nodemailer.createTransport({
    service: 'mailgun',
    auth: secret.auth
});

module.exports = {

  getDate: function() {
    var date = new Date();
    var options = {
      year: "numeric", month: "2-digit",
      day: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit"
    };
    return date.toLocaleTimeString("en-us", options);
  },

  getNewCroppedImage: function(UserUrl, website, email, params, oldImg, cb) {
    basicScraper.getScreenshot(website, UserUrl.user_id, function(img1, email) {
      // crops new image so we can compare the the old cropped image
      basicScraper.cropImg(img1, params, true, function(newImg) {
        // checks for difference in pictures
        cb(oldImg, newImg)
      }); // basicScraper.cropImg(img1, params, true, function(img2) {
    }, email); // basicScraper.getScreenshot()
  },

  compareOCR: function(UserUrl, website, email, params, oldImg, cb) {
    // TODO: take values that are input to it, pass it through compare ocr functions? Should be in basicScroperController?
    this.getNewCroppedImage(UserUrl, website, email, params, oldImg, function(oldImg, newImg) {
      console.log('inside ocrCompare, oldImg', oldImg, 'newImg', newImg);
      /*
      have: /Users/banana/Projects/gitinit/loveBiscuits/server
      want: /Users/banana/Projects/gitinit/loveBiscuits/client/
      */

        newImg = __dirname.substr(0, __dirname.length - 12) + 'client/' + newImg;
        ocr.convertImageToText(newImg, function(err, text) {
          if (err) {
            console.log('ocr error' + err);
          } else {
            console.log('comparing text values');
            if (UserUrl.filter === 'greater') {
              // pulls first set of numbers from text
              if (text.match(/\d+\.?\d*/gi)) {
                var compareVal = text.match(/\d+\.?\d*/gi)[0];
              }
              if (compareVal < UserUrl.compareVal) {
                cb(oldImg, newImg);
              }
            } else if (UserUrl.filter == 'less') {
              // TODO: pull numeric value from text
              if (text.match(/\d+\.?\d*/gi)) {
                var compareVal = text.match(/\d+\.?\d*/gi)[0];
              }
              if (compareVal > UserUrl.compareVal) {
                cb(oldImg, newImg);
              }
            } else if (UserUrl.filter == 'contains') {
              // if a user wants to check for multiple words
              var contains = UserUrl.compareVal.split(',') || UserUrl.compareVal;
              // iterate through each word
              for (var i = 0; i < contains.length; i++) {
                // if text contains any of the values
                if (text.toLowerCase().indexOf(contains[i].toLowerCase()) > -1) {
                  cb(oldImg, newImg);
                } // if (text.indexOf(contains[i])) {
              } // for (var i = 0; i < contains.length; i++) {
            }  else {
              if (UserUrl.cronVal !== text) {
               cb(oldImg, newImg);
              } // if (UserUrl.cronVal !== text) {
            };
          }; // } else {
        }); // ocr.converImageToText(newImg, function(newImg) {
    }); //this.getNewCroppedImage(UserUrl, website, email, params, oldImg, function(oldImg, newImg) {
  },

  compareScreenShot: function(UserUrl, website, email, params, oldImg, cb) {
    this.getNewCroppedImage(UserUrl, website, email, params, oldImg, function(oldImg, newImg) {
      // checks for difference in pictures
      compare(oldImg, newImg, function (equal, oldImg, newImg){
        if (!equal){
          cb(oldImg, newImg);
        }; // if (!equal){
      }); // compare(img1, img2, function (equal){
    });
  },

  sendEmail: function(website, email, oldImg, newImg) {
    console.log('change detected on', website, 'sending email to ', email);
    // parameters for email

    // TODO: Add different mail options for different comparison funcitons.
    var mailOptions = {
        // can have a null value.. Assign it in cronController?
        // greater, less, contains, text, image
        
        from: "The Blank Arrays <<EMAIL>>", // sender address
        to: email, // list of receivers
        subject: 'We found some tubular changes!', // Subject line
        text: 'Hi there! It looks like we found a change on '+ website + '!', // plaintext body
        html: "<span>The Scrapinit team found a change on " + website +"!</span>",
        attachments: [
        {
          path: oldImg
        },
        {
          path: newImg
        }
        ]
    };

{'fraction_non_alphanumeric': 0.14009944428195378, 'fraction_numerical': 0.0035097981866042704, 'mean_word_length': 2.204623555139019, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, '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': '3908186', 'n_tokens_mistral': 3068, 'n_tokens_neox': 2974, 'n_words': 795}