-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_couples.py
executable file
·66 lines (54 loc) · 1.76 KB
/
run_couples.py
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
66
#!/usr/bin/python
import sys
import random
import smtplib
def main():
if len(sys.argv)<3:
print "usage: %s <peoplefile> <smtpserver>"%sys.argv[0]
sys.exit(0)
couples=[x.strip().split(',') for x in open(sys.argv[1]).readlines()]
people={}
partners={}
for x in couples:
people[x[0]] = x[1]
people[x[2]] = x[3]
partners[x[0]] = x[2]
partners[x[2]] = x[0]
# remove emails
couples = [[x[0],x[2]] for x in couples]
ok=False
while not(ok):
ok = True
names = people.keys()
random.shuffle(names)
random.shuffle(couples)
p2p={}
for i in range(len(names)):
fr=names[i]
to=names[(i+1)%len(names)]
p2p[fr]=to
if partners[to]==fr: # p2p should not be between partners
ok = False
c2c={}
for i in range(len(couples)):
fr = couples[i]
to = couples[(i+1)%len(couples)]
c2c[fr[0]]=to
c2c[fr[1]]=to
for x in [p2p[fr[0]],p2p[fr[1]]]:
for y in [to[0],to[1]]:
if x==y:
ok=False
if p2p[x] == p2p[partners[y]]:
ok=False
if p2p[partners[x]] == p2p[y]:
ok=False
server=smtplib.SMTP(sys.argv[2])
for fr,to in p2p.iteritems():
msg="Subject: De kerstman\nFrom: \"Kerstman\" <[email protected]>\n\nBeste %s,\nJe mag dit jaar een cadeautje kopen voor %s. Samen met %s mag je een cadeautje kopen voor %s en %s. Gelieve nog even te bevestigen dat je deze mail gekregen hebt, dat spaart verwarring achteraf uit. Veel plezier!"%(fr,to,partners[fr],c2c[fr][0],c2c[fr][1])
dbg="%s voor %s en voor %s"%(fr,to,c2c[fr])
print(dbg)
server.set_debuglevel(1)
server.sendmail('Kerstman <[email protected]>',people[fr], msg)
if __name__=='__main__':
main()