Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates to work with new postageapp

  • Loading branch information...
commit b31def2e2a11c26b1b9b5a8221b7de297bb6d856 1 parent f7ee188
@gerad gerad authored
Showing with 29 additions and 10 deletions.
  1. +29 −10 scripts/judges-nag-one.coffee
View
39 scripts/judges-nag-one.coffee
@@ -3,18 +3,37 @@ env = require '../config/env'
mongoose = require('../models')(env.mongo_url)
util = require 'util'
postageapp = require('postageapp')(env.secrets.postageapp)
+_ = require('underscore')
+async = require('async')
Vote = mongoose.model 'Vote'
Person = mongoose.model 'Person'
-Person.find { role: 'judge', email: /@/, twitterScreenName: /\w/ }, (err, judges) ->
- throw err if err
- judges.forEach (judge) ->
- Vote.count { personId: judge.id }, (err, count) ->
- throw err if err
- if count is 0
- util.log "Sending 'judge_nag_one' to '#{judge.email}' (#{count})".yellow
- postageapp.apiCall judge.email, 'judge_nag_one', null, null,
- id: judge.id
+nag = (judge, callback) ->
+ Vote.count { personId: judge.id }, (err, count) ->
+ return callback(err) if err
+
+ email = judge.email.replace(/\.nodeknockout\.com$/, '')
+
+ alreadySent = _.include([
+ # redacted
+ ], email)
+
+ if !alreadySent and count is 0
+ util.log "Sending 'judge_nag_one' to '#{email}' (#{count})".yellow
+ postageapp.sendMessage
+ recipients: email,
+ template: 'judge_nag_one'
+ variables:
first_name: judge.name.split(/\s/)[0]
- else util.log "Skipping '#{judge.email}' (#{count})"
+ , callback
+ else
+ util.log "Skipping '#{email}' (#{count})"
+ callback()
+
+Person.find { role: 'judge', email: /@/ }, (err, judges) ->
+ throw err if err
+
+ async.forEachSeries judges, nag, (err) ->
+ util.error(err) if err
+ mongoose.connection.close()
Please sign in to comment.
Something went wrong with that request. Please try again.