-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (28 loc) · 1.04 KB
/
Copy pathmain.py
File metadata and controls
34 lines (28 loc) · 1.04 KB
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
# -*- coding: utf-8 -*-
import sys
import csv
import sendEmail
import random
if __name__ == '__main__':
santas = sys.argv[1]
santaDictionary = {}
with (open(santas)) as santaFile:
readSantas = csv.reader(santaFile)
for row in readSantas:
name = row[0]
email = row[1]
santaDictionary[email] = name
randomKeyOrder = list(santaDictionary.keys())
random.shuffle(randomKeyOrder)
with open('santa_solution','w') as solutionFile:
last = len(randomKeyOrder) -1
for i, key in enumerate(randomKeyOrder):
solutionFile.write(key + '\n') #keep record of santa list, to reveal at end
santa = santaDictionary[randomKeyOrder[i]]
if i == last:
santee = santaDictionary[randomKeyOrder[0]]
else:
santee = santaDictionary[randomKeyOrder[i+1]]
message = sendEmail.constructMessage(santa,santee)
toEmailAddress = key
sendEmail.send(toEmailAddress,message)