Skip to content

Commit 2b48861

Browse files
author
Gerad Suyderhoud
committed
nag emails
- update second judge reminder email - remind top contestants to update videos
1 parent 4160dc1 commit 2b48861

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

scripts/contestant-video-nag.coffee

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'colors'
2+
env = require '../config/env'
3+
mongoose = require('../models')(env.mongo_url)
4+
util = require 'util'
5+
postageapp = require('postageapp')(env.secrets.postageapp)
6+
_ = require('underscore')
7+
async = require('async')
8+
9+
Team = mongoose.model 'Team'
10+
Person = mongoose.model 'Person'
11+
12+
nagTeam = (team, callback) ->
13+
team.people (err, people) ->
14+
return callback(err) if err
15+
emailable = (person for person in people when /@/.test(person.email))
16+
util.log "Sending 'contestant_video_nag' to '#{team.name}'".yellow
17+
async.forEach emailable, nagPerson, callback
18+
19+
nagPerson = (person, callback) ->
20+
email = person.email.replace(/\.nodeknockout\.com$/, '')
21+
name = person.name or person.slug
22+
firstName = name?.split(/\s+/)[0] ? ''
23+
24+
address = if name
25+
"\"#{name}\" <#{email}>"
26+
else
27+
email
28+
util.log "\t -> #{address} (#{firstName})".yellow
29+
30+
postageapp.sendMessage
31+
recipients: address
32+
template: 'contestant_video_nag'
33+
variables:
34+
first_name: " #{firstName}"
35+
, callback
36+
37+
Team.find { 'entry.votable': true, 'entry.videoURL': '', 'scores.overall': { $gt: 15 }}, (err, teams) ->
38+
throw err if err
39+
40+
async.forEachSeries teams, nagTeam, (err) ->
41+
util.error(err) if err
42+
mongoose.connection.close()

scripts/judges-nag-two.coffee

+26-11
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@ env = require '../config/env'
33
mongoose = require('../models')(env.mongo_url)
44
util = require 'util'
55
postageapp = require('postageapp')(env.secrets.postageapp)
6+
_ = require('underscore')
7+
async = require('async')
68

79
Vote = mongoose.model 'Vote'
810
Person = mongoose.model 'Person'
911

10-
Person.find { role: 'judge', email: /@/, twitterScreenName: /\w/ }, (err, judges) ->
12+
nag = (judge, callback) ->
13+
email = judge.email.replace(/\.nodeknockout\.com$/, '')
14+
15+
alreadySent = _.include([
16+
# redacted
17+
], email)
18+
19+
if !alreadySent
20+
util.log "Sending 'judge_nag_two' to '#{email}'".yellow
21+
postageapp.sendMessage
22+
recipients: email,
23+
template: 'judge_nag_two'
24+
variables:
25+
first_name: judge.name.split(/\s/)[0]
26+
, callback
27+
else
28+
util.log "Skipping '#{email}'"
29+
callback()
30+
31+
Person.find { role: 'judge', email: /@/ }, (err, judges) ->
1132
throw err if err
12-
judges.forEach (judge) ->
13-
Vote.count { personId: judge.id }, (err, count) ->
14-
throw err if err
15-
votes_left = 10 - count
16-
if votes_left > 0
17-
util.log "Sending 'judge_nag_two' to '#{judge.email}' (#{count})".yellow
18-
postageapp.apiCall judge.email, 'judge_nag_two', null, null,
19-
first_name: judge.name.split(/\s/)[0]
20-
votes_left: if votes_left is 1 then '1 vote' else "#{votes_left} votes"
21-
else util.log "Skipping '#{judge.email}' (#{count})"
33+
34+
async.forEachSeries judges, nag, (err) ->
35+
util.error(err) if err
36+
mongoose.connection.close()

0 commit comments

Comments
 (0)