-
Notifications
You must be signed in to change notification settings - Fork 4
/
Kris_Kingle.py
77 lines (53 loc) · 1.98 KB
/
Kris_Kingle.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
67
68
69
70
71
72
#Random allotment and secretly mailing the allotment details to each participant.
import numpy as np
import pandas as pd
import smtplib
participants = {
'Vikas' : 'Email ID of Vikas', #Example: 'abc@gmail.com'
'Dev' : 'Email ID of Dev', #Example: 'bbc@gmail.com'
'Mahek' : 'Emai ID of Mahek', #Example: 'cbc@gmail.com'
'Akash' : 'Email ID of Akash', #Example: 'dbc@gmail.com'
'Vishal' : 'Email ID of Vishal' #Example: 'lbc@gmail.com'
}
#set groups of people which must not gift each other, 0 means no constrains, every other number is a group
constrains = {
'Vikas' : 0,
'Dev' : 0,
'Mahek' : 1,
'Akash' : 1,
'Vishal' : 0
}
def setRandom():
santa = list(np.random.choice(list(participants.keys()), len(list(participants.keys())), replace = False))
receiver = []
for i in range(-1, len(santa)-1):
receiver.append(santa[i])
return santa, receiver
def checkConstrains():
for i in range(len(santa)):
print(i, santa[i], constrains[santa[i]], receiver[i], constrains[receiver[i]], sep = ' | ', end = '\n')
if santa[i]==receiver[i]:
return False
if constrains[santa[i]] and constrains[santa[i]] == constrains[receiver[i]]: #se il vincolo è diverso da 0 oppure se sono uguali
return False
return True
santa, receiver = setRandom()
while not checkConstrains():
santa, receiver = setRandom()
print(santa, receiver)
#Keep less secured apps option turned on from your gmail account to avoid error while sending out the mail.
smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
smtpObj.ehlo()
smtpObj.starttls()
email = input('Enter your email: ')
password = input('Enter your password: ')
smtpObj.login(email, password)
for j in range(len(participants)):
smtpObj.sendmail(email, participants[santa[j]], \
'Subject: Secret Santa 2022 \
\nHo Ho Ho %s! \
\n\nChristmas is almost here, \
\n\nThis year you are gifting to....... %s!' % (santa[j], receiver[j]))
smtpObj.quit()
#df = pd.DataFrame({'santa':santa, 'receiver':receiver})
#df.to_csv('Kris Kingle list.csv')