<commit_before>'use strict';

var moment = require('moment')
var MailGun = require('mailgun-es6')
var _ = require('lodash')

var appSettings = require('../db/appSettings')
var pagesdb = require('../db/pagesdb')
var APIKEYS = require('../../config/apikeys.json')

var bookmarkExpiry = {}
var setTimeoutRef = null
var checkInterval = moment().add(3, 'hours') - moment()
var mailGun = new MailGun({
  privateApi: APIKEYS.mailgunPrivateApiKey,
  publicApi: APIKEYS.mailgunPublicApiKey,
  domainName: 'mailgun.coopcoding.com'
})


function shouldWeRunBookmarkExpiryCheck() {
  var bookmarkExpiryLastCheck = appSettings.settings.bookmarkExpiryLastCheck
  var bookmarkExpiryMonths = appSettings.settings.bookmarkExpiryMonths
  console.log(`bookmarkExpiryLastCheck : ${bookmarkExpiryLastCheck}`)
  console.log(`bookmarkExpiryMonths : ${bookmarkExpiryMonths}`)
  var timestampMonthsFromNow = moment(bookmarkExpiryLastCheck).add(bookmarkExpiryMonths, 'M').valueOf()
  console.log(`timestampMonthsFromNow : ${timestampMonthsFromNow}`)
  var returnValue = timestampMonthsFromNow < Date.now()
  console.log(`shouldWeRunBookmarkExpiryCheck result: ${returnValue}`)
  return returnValue
}

/****
 * sendExpiredBookmarksEmail needs to be inside the if(rows.length){,
 * also, put appSettings.update() before sendExpiredBookmarksEmail so it definately runs
 * and doesn't get skipped if sendExpiredBookmarksEmail errors.
 * .where('checkedForExpiry', 0) is checking against 0 because SQLite stores Boolean values
 * as a 0 for false or 1 for true.
 *
 * note: the ".where(function() {}" needs to be a regular function or the "this" context is wrong
 */
function checkForExpiredBookmarks() {
  console.log('checkForExpiredBookmarks running')
  var expiryTimestamp = Date.now()
  pagesdb.db('pages')
    .where('dateCreated', '<', expiryTimestamp)
    .where(function() {<commit_msg>Minor change to bookmarkExpiry<commit_after>'use strict';

var moment = require('moment')
var MailGun = require('mailgun-es6')
var _ = require('lodash')

var appSettings = require('../db/appSettings')
var pagesdb = require('../db/pagesdb')
var APIKEYS = require('../../config/apikeys.json')

var bookmarkExpiry = {}
var setTimeoutRef = null
var checkInterval = moment().add(3, 'hours') - moment()
var mailGun = new MailGun({
  privateApi: APIKEYS.mailgunPrivateApiKey,
  publicApi: APIKEYS.mailgunPublicApiKey,
  domainName: 'mailgun.coopcoding.com'
})


function shouldWeRunBookmarkExpiryCheck() {
  var bookmarkExpiryLastCheck = appSettings.settings.bookmarkExpiryLastCheck
  var bookmarkExpiryMonths = appSettings.settings.bookmarkExpiryMonths
  console.log(`bookmarkExpiryLastCheck : ${bookmarkExpiryLastCheck}`)
  console.log(`bookmarkExpiryMonths : ${bookmarkExpiryMonths}`)
  var timestampMonthsFromNow = moment(bookmarkExpiryLastCheck).add(bookmarkExpiryMonths, 'months').valueOf()
  console.log(`timestampMonthsFromNow : ${timestampMonthsFromNow}`)
  var returnValue = timestampMonthsFromNow < Date.now()
  console.log(`shouldWeRunBookmarkExpiryCheck result: ${returnValue}`)
  return returnValue
}

/****
 * sendExpiredBookmarksEmail needs to be inside the if(rows.length){,
 * also, put appSettings.update() before sendExpiredBookmarksEmail so it definately runs
 * and doesn't get skipped if sendExpiredBookmarksEmail errors.
 * .where('checkedForExpiry', 0) is checking against 0 because SQLite stores Boolean values
 * as a 0 for false or 1 for true.
 *
 * note: the ".where(function() {}" needs to be a regular function or the "this" context is wrong
 */
function checkForExpiredBookmarks() {
  console.log('checkForExpiredBookmarks running')
  var expiryTimestamp = Date.now()
  pagesdb.db('pages')
    .where('dateCreated', '<', expiryTimestamp)
    .where(function() {
{'fraction_non_alphanumeric': 0.11893333333333334, 'fraction_numerical': 0.0032, 'mean_word_length': 5.8699633699633695, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '347044', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1160, 'n_words': 273}