<commit_before>var moment = require('moment');
var email = require('../core/app_modules/email');
var user = require('../core/app_modules/user');
var inv = require('../core/app_modules/inventory');
var co = require('co');
var extend = require('extend');

const YESTERDAY = moment().subtract(1, 'days');
const TOMORROW = moment().add(1, 'days');
const NOW = moment();

var run = co.wrap(function*(from_date, to_date, type) {
  console.log("%s: Sending %s emails.", new Date, type);
  var items = (yield inv.checked_out).filter(function(item) {
    var due = item.due;
    return moment(due).isBefore(to_date) && moment(due).isAfter(from_date);
  });

  if(!items.length) {
    console.log("%s: Nobody to send %s emails to today.", new Date, type);
    process.exit();
  }

  var to_email = {};

  for(var i in items) {
    var owner = items[i].owner;

    if(!to_email[owner]) {
      to_email[owner] = {
        items: [],
        name: null, // filled in below
        email: null // filled in below
      }
    }

    to_email[owner].items.push({
      item: items[i].name,
      due: items[i].due
    });
  }

  var users = Object.keys(to_email);
  to_email = extend(true, to_email, yield user.contactInfo.apply(this, users));

  for(var j in to_email) {
    var data = to_email[j];
    console.log("%s: emailing %s (Netid: %s, Email: %s) about", new Date(), data.name, data.email, j, data.items);
    var fn = (type === 'overdue' ? email.overdue : email.reminder);
    yield fn(data.items, data.name, data.email);
  }
});

var promise = null;

switch(process.argv[2]) {
  case '--overdue':
    promise = run.bind(this, YESTERDAY, NOW, 'overdue');
    break;
  case '--reminder':<commit_msg>Close GH-324: Resolves #323.<commit_after>var moment = require('moment');
var email = require('../core/app_modules/email');
var user = require('../core/app_modules/user');
var inv = require('../core/app_modules/inventory');
var co = require('co');
var extend = require('extend');

const DAY_BEFORE_YESTERDAY = moment().subtract(2, 'days');
const YESTERDAY = moment().subtract(1, 'days');
const TOMORROW = moment().add(1, 'days');
const NOW = moment();

var run = co.wrap(function*(from_date, to_date, type) {
  console.log("%s: Sending %s emails.", new Date, type);
  var items = (yield inv.checked_out).filter(function(item) {
    var due = item.due;
    return moment(due).isBefore(to_date) && moment(due).isAfter(from_date);
  });

  if(!items.length) {
    console.log("%s: Nobody to send %s emails to today.", new Date, type);
    process.exit();
  }

  var to_email = {};

  for(var i in items) {
    var owner = items[i].owner;

    if(!to_email[owner]) {
      to_email[owner] = {
        items: [],
        name: null, // filled in below
        email: null // filled in below
      }
    }

    to_email[owner].items.push({
      item: items[i].name,
      due: items[i].due
    });
  }

  var users = Object.keys(to_email);
  to_email = extend(true, to_email, yield user.contactInfo.apply(this, users));

  for(var j in to_email) {
    var data = to_email[j];
    console.log("%s: emailing %s (Netid: %s, Email: %s) about", new Date(), data.name, data.email, j, data.items);
    var fn = (type === 'overdue' ? email.overdue : email.reminder);
    yield fn(data.items, data.name, data.email);
  }
});

var promise = null;

switch(process.argv[2]) {
  case '--overdue':
    promise = run.bind(this, DAY_BEFORE_YESTERDAY, YESTERDAY, 'overdue');
    break;
  case '--reminder':
{'fraction_non_alphanumeric': 0.18004026459591602, 'fraction_numerical': 0.003738855335058959, 'mean_word_length': 3.369346733668342, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5419682', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1208, 'n_words': 296}