Permalink
Browse files

nag emails

- update second judge reminder email
- remind top contestants to update videos
  • Loading branch information...
1 parent 4160dc1 commit 2b48861488efe0aed913da6c978b656e5c179336 @gerad gerad committed Nov 15, 2012
Showing with 68 additions and 11 deletions.
  1. +42 −0 scripts/contestant-video-nag.coffee
  2. +26 −11 scripts/judges-nag-two.coffee
@@ -0,0 +1,42 @@
+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')
+
+Team = mongoose.model 'Team'
+Person = mongoose.model 'Person'
+
+nagTeam = (team, callback) ->
+ team.people (err, people) ->
+ return callback(err) if err
+ emailable = (person for person in people when /@/.test(person.email))
+ util.log "Sending 'contestant_video_nag' to '#{team.name}'".yellow
+ async.forEach emailable, nagPerson, callback
+
+nagPerson = (person, callback) ->
+ email = person.email.replace(/\.nodeknockout\.com$/, '')
+ name = person.name or person.slug
+ firstName = name?.split(/\s+/)[0] ? ''
+
+ address = if name
+ "\"#{name}\" <#{email}>"
+ else
+ email
+ util.log "\t -> #{address} (#{firstName})".yellow
+
+ postageapp.sendMessage
+ recipients: address
+ template: 'contestant_video_nag'
+ variables:
+ first_name: " #{firstName}"
+ , callback
+
+Team.find { 'entry.votable': true, 'entry.videoURL': '', 'scores.overall': { $gt: 15 }}, (err, teams) ->
+ throw err if err
+
+ async.forEachSeries teams, nagTeam, (err) ->
+ util.error(err) if err
+ mongoose.connection.close()
@@ -3,19 +3,34 @@ 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) ->
+nag = (judge, callback) ->
+ email = judge.email.replace(/\.nodeknockout\.com$/, '')
+
+ alreadySent = _.include([
+ # redacted
+ ], email)
+
+ if !alreadySent
+ util.log "Sending 'judge_nag_two' to '#{email}'".yellow
+ postageapp.sendMessage
+ recipients: email,
+ template: 'judge_nag_two'
+ variables:
+ first_name: judge.name.split(/\s/)[0]
+ , callback
+ else
+ util.log "Skipping '#{email}'"
+ callback()
+
+Person.find { role: 'judge', email: /@/ }, (err, judges) ->
throw err if err
- judges.forEach (judge) ->
- Vote.count { personId: judge.id }, (err, count) ->
- throw err if err
- votes_left = 10 - count
- if votes_left > 0
- util.log "Sending 'judge_nag_two' to '#{judge.email}' (#{count})".yellow
- postageapp.apiCall judge.email, 'judge_nag_two', null, null,
- first_name: judge.name.split(/\s/)[0]
- votes_left: if votes_left is 1 then '1 vote' else "#{votes_left} votes"
- else util.log "Skipping '#{judge.email}' (#{count})"
+
+ async.forEachSeries judges, nag, (err) ->
+ util.error(err) if err
+ mongoose.connection.close()

0 comments on commit 2b48861

Please sign in to comment.