-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanta.py
executable file
·40 lines (34 loc) · 1.03 KB
/
santa.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
#! /usr/bin/env python
import yagmail
import json
import sys
import csv
from random import shuffle
with open('data.json') as f_data:
data = json.load(f_data)
YAG = yagmail.SMTP(str(data["email"]), str(data["password"]))
def sendMail(name, otherName, email):
txt="Hi %s,\nThis is Dan's secret santa script. Your assignment is %s. Try not to get something shitty!\n\nLove,\nRobot" % (name, otherName)
YAG.send(email, "Secret santa assignment!!!111!!!", txt)
def csvParse(fName):
with open(fName, 'r') as csvFile:
reader = csv.reader(csvFile, delimiter=",")
return [(row[1], row[2]) for row in reader]
def assign(users):
shuf = list(users)
shuffle(shuf)
l = []
for i in range(len(shuf)):
nxt = i + 1 if i < len(shuf) - 1 else 0
(name, email) = shuf[i]
(nxtName, _) = shuf[nxt]
l.append((name, nxtName, email))
return l
if __name__ == '__main__':
if len(sys.argv) < 2:
print "How about you give me a CSV File"
exit(1)
users = csvParse(sys.argv[1])
assignments = assign(users)
for data in assignments:
sendMail(*data)