-
Notifications
You must be signed in to change notification settings - Fork 7
/
send_invites.rb
65 lines (46 loc) · 1.27 KB
/
send_invites.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require "active_support"
require "active_support/all"
require "./send_emails"
require "redis"
$REDIS = Redis.new
if $REDIS.get "ran_recently"
puts "Nothing to do, last ran at #{$REDIS.get("last_ran")}"
exit
end
# People are stored as a big ol' string in redis
people_txt = $REDIS.get "people"
people = people_txt.strip.split("\n").map do |line|
pieces = line.split " "
[pieces[0...-1].join(" "), pieces.last]
end
def good_pairings(people)
#TODO: check for no recent duplicates (within the last three weeks)
true
end
while true do
people.shuffle!
break if good_pairings(people)
end
loner = people.pop if people.size % 2 == 1
pairings = people.each_slice(2).map do |a, b|
[a, b]
end
# Add third wheel if we have a loner
if loner
pairings.sample.push loner
end
pairings.each_with_index do |pairing, index|
puts "#{index}: #{pairing.inspect}"
end
$REDIS.set "pairings", pairings.inspect
pairings.each_with_index do |pairing, index|
email_addresses = pairing.map(&:last)
print email_addresses.inspect
# Assuming being sent out on Friday morning
start_time = 5.days.from_now.at_noon
send_emails pairing
puts " DONE!"
end
$REDIS.set "last_ran", Time.now
$REDIS.set "ran_recently", true
$REDIS.expire "ran_recently", (1.week.from_now - Time.now).to_i - 7200