Advertisement
Guest User

Gugsmas Secret Santa Code

a guest
Dec 11th, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.72 KB | None | 0 0
  1. import smtplib
  2. import random
  3.  
  4. # Define mailing targets names and their corresponding email addresses.
  5. mailingAccountList = [{"Andrew" :"ceciltitanwave@gmail.com"},
  6.                       {"Maddie" :"mwooden1@binghamton.edu"},
  7.                       {"Tyler"  :"tmille20@binghamton.edu"},
  8.                       {"Alex"   :"aebange@gmail.com"},
  9.                       {"Nick"   :"nick.miller.2000.nm@gmail.com"},
  10.                       {"Gillian":"gilliankhulbert@gmail.com"},
  11.                       {"James"  :"jamesdfarrow14@gmail.com"},
  12.                       {"Clare"  :"clare_osborn9@aol.com"}]
  13.  
  14. mailingAccountsDict = {"Andrew": "ceciltitanwave@gmail.com",
  15.                       "Maddie" : "mwooden1@binghamton.edu",
  16.                       "Tyler"  : "tmille20@binghamton.edu",
  17.                       "Alex"   : "aebange@gmail.com",
  18.                       "Nick"   : "nick.miller.2000.nm@gmail.com",
  19.                       "Gillian": "gilliankhulbert@gmail.com",
  20.                       "James"  : "jamesdfarrow14@gmail.com",
  21.                       "Clare"  : "clare_osborn9@aol.com"}
  22.  
  23. # Define sender's account information
  24. userName = "GugsXMas2018@gmail.com"
  25. userPass = "Gugs2018"
  26.  
  27. # Define the location and port of the desired SMTP server
  28. mail = smtplib.SMTP("smtp.gmail.com", 587)
  29.  
  30. def randomNumbers():
  31.     numbers_list = [i for i in range(len(mailingAccountList))]
  32.     return numbers_list
  33.  
  34. # Assign targets to participants
  35. def santasList(x):
  36.     # Instantiate lists and variables
  37.     givers_list = x
  38.     receivers_list = x
  39.     pairs_list = []
  40.     naughty_list = []
  41.     i = 0
  42.     z = True
  43.     remaining_names_list = []
  44.     # Create a localized list of all the names
  45.     for item in mailingAccountList:
  46.         remaining_names_list.append(list(item)[0])
  47.     mailing_accounts_length = len(mailingAccountList)+1
  48.     # Create two localized lists of numbers to be randomized with corresponding list items
  49.     while z == True:
  50.         for item in tuple(x):
  51.             # Define a santa
  52.             santa = item
  53.             # Define a child
  54.             child = random.choice(receivers_list)
  55.             # Check to make sure the child isn't the same as the santa
  56.             if santa == child:
  57.                 child2 = random.choice(receivers_list)
  58.                 # The RNG is being a bitch and your child is the same as the santa
  59.                 if santa == child:
  60.                     # The random number generator is being a REALLY BIG fucking bitch and we need to rerun the ENTIRE for loop
  61.                     break
  62.                 else:
  63.                     # Return to standard operation
  64.                     break
  65.             else:
  66.                 # The child is now going to get a gift, remove them from the list
  67.                 receivers_list.remove(child)
  68.                 # Add the pair to the list of pairs
  69.                 pairs_list.append({santa : child})
  70.                 # Check to see if there's anyone still unaccounted for
  71.                 if len(receivers_list) == 0:
  72.                     # Everyone has been assigned, time to move on
  73.                     z = False
  74.                 else:
  75.                     # There is still work to be done, continue
  76.                     pass
  77.     # We now have our pairs list, time to change numbers to names
  78.     for item in pairs_list:
  79.         # Retrieve the value from the current key
  80.         current_number = list(item.values())[0]
  81.         # Replace the key values with names
  82.         naughty_list.append({remaining_names_list[i]: remaining_names_list[current_number]})
  83.         i+=1
  84.     # Return the naughty list so we can mail it
  85.     return naughty_list
  86.  
  87.  
  88. # Launch the reindeer to deliver the naughty list to the secret Santa's inboxes
  89. def launchReindeer(naughtyList):
  90.     # Parse through the items in our "naughty list"
  91.     for item in naughtyList:
  92.         # Separate the keys and their corresponding values
  93.         key = (list(item)[0])
  94.         # Take the key and find it's corresponding email
  95.         email_target = mailingAccountsDict[key]
  96.         subject = "GUG XMAS SECRET SANTA TARGET 12/29/18"
  97.         value = (""""
  98.        To: %s <%s>
  99.        From: GUGBLASTER9000 2.15
  100.        
  101.        Greetings fellow gug,
  102.        
  103.        In anticipation of our upcoming Christmas party, December 29th - we are sending out a 'Secret Santa' list. You are receiving this email because you did not opt out of the Secret Santa activities.
  104.        If you would like to opt out, tell Rudy IMMEDIATELY. At the bottom of this email, you should see a name - if you don't, Alex is currently at his computer swearing profusely.
  105.        The name at the bottom represents the person you should be buying a secret gift for.
  106.        The spending limit is currently set at $20.00, if you go significantly below the limit you will look like Cam, and if you go over the limit you will look like a COMPLETE FOOL.
  107.        Remember to get something soon as the date is only 18 days away (from the date this was sent).
  108.        
  109.        THE PERSON YOU WILL GIVE A GIFT TO IS: %s.""" % (key,email_target,item[key]))
  110.         msg = 'Subject: {}\n\n{}'.format(subject, value)
  111.         # Dispatch the reindeer
  112.         mail.sendmail(userName,email_target,msg)
  113.         print("Sent target to %s at %s." % (key, email_target))
  114.  
  115. # Generate a dictionary of randomly generated paired numbers
  116. numbersList = randomNumbers()
  117.  
  118. # Generate a dictionary containing randomly paired names
  119. naughtyList = santasList(numbersList)
  120.  
  121. # Identify ourselves to the SMTP server
  122. mail.ehlo()
  123.  
  124. # Enable transport layer security (TLS) encryption
  125. mail.starttls()
  126.  
  127. # Login to our email account
  128. mail.login(userName,userPass)
  129.  
  130. # Dispatch the reindeer to send our message
  131. launchReindeer(naughtyList)
  132.  
  133. # Close the stables and pack up shop
  134. mail.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement