Skip to content

Instantly share code, notes, and snippets.

@mcomisso
Created December 12, 2017 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcomisso/e20b06cfcd085f6dad235e170f22e13f to your computer and use it in GitHub Desktop.
Save mcomisso/e20b06cfcd085f6dad235e170f22e13f to your computer and use it in GitHub Desktop.
import json
import random
import pandas as pd
import sys
sys.setrecursionlimit(1500)
class Person:
def __eq__(self, other):
return self.name == other.name
def __str__(self):
return "" + self.name + ", " + self.email
def __init__(self, name, email):
self.name = name
self.email = email
self.isSanta = False
self.isTarget = False
def becomeSanta(self):
self.isSanta = True
def becomeTarget(self):
self.isTarget = True
class Rudolph:
def __init__(self):
self.santa = None
self.target = None
def pickSanta(self, people):
for i in range(0, 100):
random.shuffle(people)
self.santa = people[0]
if self.santa.isSanta or self.santa is self.target:
self.pickSanta(people)
else:
self.santa.becomeSanta()
def pickTarget(self, people):
for i in range(0, 100):
random.shuffle(people)
self.target = people[0]
if self.target.isTarget or self.target is self.santa:
self.pickTarget(people)
else:
self.target.becomeTarget()
def returnCouple(self):
return [self.santa, self.target]
class Mailer:
EMAIL = "MAIN SENDER EMAIL"
PASS = "PASSWORD"
def sendEmail(self, person, santaPerson):
import smtplib
from email.mime.text import MIMEText
text = "HO HO HO! " + santaPerson.name + ", questo anno sarai il secret santa di **" + person.name + "**."
text += "\nRules:\n"
text += """
* Prima regola del Secret Santa: non parlate mai del Secret Santa.
* Seconda regola del Secret Satan: non dovete parlare mai del Secret Santa.
* Terza regola del Secret Santa: se qualcuno si accascia, e' spompato, grida basta, fine del regalo.
* Quarta regola del Secret Santa: si regala solo due per volta.
* Quinta regola del Secret Santa: un regalo alla volta ragazzi.
* Sesta regola del Secret Santa: niente camicia, niente scarpe.
* Settima regola del Secret Santa: lo scarto dei regali dura per tutto il tempo necessario.
* Ottava regola del Secret Santa: se questa e' la vostra prima sera al Secret Santa, dovete regalare.
* Nona regola ed ultima regola del Secret Santa: Budget intorno i 10 euro.
"""
msg = MIMEText(text)
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'Secret Santa 2017!'
msg['From'] = self.EMAIL
msg['To'] = santaPerson.email
# Send the message via our own SMTP server.
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(self.EMAIL, self.PASS)
s.send_message(msg)
s.quit()
URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vTboGrqsfJLgbuFVU27O7jv1wu6jN4zsORyHG-U5z1EVR0zmu4JL186ARgN9TZikdk8SJ9IljSLgrYT/pub?gid=752693825&single=true&output=csv"
csvfile = open('./ssanta.csv', 'r')
csv = pd.read_csv(csvfile).to_json(orient="index")
dict = json.loads(csv)
people = []
def loadPeople():
for key, value in dict.items():
person = Person(value["Nome"], value["Indirizzo email"])
people.append(person)
loadPeople()
couples = []
for person in people:
rudolph = Rudolph()
rudolph.pickTarget(people)
rudolph.pickSanta(people)
couples.append(rudolph.returnCouple())
for couple in couples:
print("Done")
Mailer().sendEmail(couple[0], couple[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment