Skip to content
Browse files

third (and final) judge nag

  • Loading branch information...
1 parent 0dcae6e commit abda4ce791ed2567b4959a8dc0e83fee82f7bfd2 @gerad gerad committed Nov 16, 2012
Showing with 40 additions and 0 deletions.
  1. +40 −0 scripts/judges-nag-three.coffee
View
40 scripts/judges-nag-three.coffee
@@ -0,0 +1,40 @@
+require 'colors'
+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'
+
+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 < 9
+ util.log "Sending 'judge_nag_three' to '#{email}' (#{count})".yellow
+ postageapp.sendMessage
+ recipients: email,
+ template: 'judge_nag_three'
+ variables:
+ first_name: judge.name.split(/\s/)[0]
+ entries_left: 10 - 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()

0 comments on commit abda4ce

Please sign in to comment.
Something went wrong with that request. Please try again.