-
Notifications
You must be signed in to change notification settings - Fork 2
/
gifts.py
executable file
·66 lines (55 loc) · 2.42 KB
/
gifts.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
#!/usr/bin/python
import random,sys,os
def pick_recipient(group,recipients,single_flag):
for person in group:
#print "Group=%s" % group
#print "Person=%s" % person
#print "Possibles length = %d list=%s" % (len(recipients),recipients)
gift = random.choice(recipients)
if single_flag == 0:
while gift in group:
gift = random.choice(recipients)
else:
while gift in person:
gift = random.choice(recipients)
mail_list.append( '%s=%s' %(person,gift))
#print "Gift=%s\n##############" % gift
recipients.remove(gift)
return recipients
def finalize_mail_commands():
print mail_list
#if this question is not displayed you are in an endless loop trying to select the gift for the last person
send_mail = raw_input('Program has successfully completed choosing all pairings, send emails?(y/n) ')
if (send_mail == 'n') or (send_mail == ''):
exit(1)
elif send_mail == 'y':
for item in mail_list:
sep = item.split('=')
pfrom = sep[0].split(':')
pto = sep[1].split(':')
os.system('echo HoHoHo %s! You will be buying a gift for %s this year. The decided limit is \$50. > test.txt' % (pfrom[0],pto[0]))
cmd = "timeout 10m mutt -e 'set realname=\'Santa\'' -a xmas-joke.jpg -s \'Gift Exchange 2016\' -- %s < ~/git/secret_santa/test.txt" % pfrom[1]
#os.system(cmd)
print cmd
else:
print "Invalid Input: Please type either y to continue or n to exit"
exit(2)
if __name__ == "__main__":
global mail_list
mail_list = []
#create lists of people, group couples at beginning or end of list and the singles opposite
all_recipients = ['name_1-CoupleA: [email protected]','name_2-CoupleA: [email protected]',
'name_3-CoupleB: [email protected]','name_4: [email protected]',
'name_5-Single: [email protected]','name_6-Single: [email protected]']
#create couples and lists of singles to make sure couples don't get their other half
#modify the groups to match the list of people from above
coupleA = all_recipients [0:2]
coupleB = all_recipients [2:4]
single = all_recipients [4:]
#keep initial list in tact
possible_recipients = all_recipients
#modify the groups to match what the input list is
possible_recipients = pick_recipient(coupleA,possible_recipients,single_flag=0)
possible_recipients = pick_recipient(coupleB,possible_recipients,single_flag=0)
possible_recipients = pick_recipient(single,possible_recipients,single_flag=1)
finalize_mail_commands()