@argthe1st/

Secret Santa Program!!!

Python

Only I can really use this program... But what it does is it emails people at my school and tells them what to gift to who.

fork
loading
Files
  • main.py
  • Santa-e88bac1d335a.json
main.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
73
74
75
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import random
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# Stupid complex authentication stuff
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('Santa-e88bac1d335a.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open('Secret Santa').sheet1

# Make the headers
cell_list = wks.range('A1:F1')
headers = ['Sender', 'Email', 'Reciver', 'Wishlist Item #1', 'Wishlist Item #2', 'Wishlist Item #3']
pos = 0
for cell in cell_list:
    cell.value = headers[pos]
    pos += 1

wks.update_cells(cell_list)

# Make the actual spreadsheet
cell_list = wks.range('A2:F22')
sender = []#This was filled with name and email
SENDER = [i for i in sender]
reciver = []#This was filled with what the people wanted
pos = 0
person = 0
for cell in cell_list:
    if pos == 0 or pos == 1 and len(sender) != 0:
        if pos == 0:
            randomSender = random.randint(0, len(sender)-1)
            while sender[randomSender][0] == reciver[person][0]:
                randomSender = random.randint(0, len(sender)-1)
        cell.value = sender[randomSender][pos]
        if pos == 1:
            del sender[randomSender]
    else:
        cell.value = reciver[person][pos-2]
    pos+=1
    if pos == 6:
        pos = 0
        person += 1

wks.update_cells(cell_list)
'''
# Email ppl
for person in range(len(SENDER)-1):
    cell_list = wks.findall(SENDER[person][0])
    for cell in cell_list:
        if cell.col == 1:
            body = "***THIS IS A TEST***\n***A couple people were added and they wanted a demonstration :)***\nHello Guys! Secret Santa has begun! \nThe person you have to give a gift to is " + wks.cell(cell.row, 3).value+".\n\nPreferences:\n1. "+wks.cell(cell.row, 4).value+"\n2. "+wks.cell(cell.row, 5).value+"\n3. "+wks.cell(cell.row, 6).value+"\n\nHappy Holidays!"
    msg = MIMEMultipart()
    print(person)
    print(SENDER[person][1])
    toaddr = SENDER[person][1]
    msg['To'] = SENDER[person][1]
    fromaddr = "[email protected]"
    msg['From'] = '[email protected]'
    msg['Subject'] = "Secret Santa!"
    msg.attach(MIMEText(body, 'plain'))
 
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(fromaddr, "secretsanta123")
    text = msg.as_string()
    server.sendmail(fromaddr, toaddr, text)
    server.quit()
'''