Assign a secret santa over email
Project description
A Python project to randomly pair Secret Santa gifters and recipients, following a set of constraints, and email them, all without the operator seeing the assignments.
Requirements
yagmail
Installation
Install with pip3 install santa or python3 -m pip install santa. Precede either command with sudo if it fails due to insufficient permissions.
Usage
Create Person objects for all participants with their names and addresses:
import santa
john = santa.Person('John Doe', 'jdoe@example.com')
sally = santa.Person('Sally Salamander', 'sally@mander.com')
linus = santa.Person('Linus Torvalds', 'torvalds@transmeta.com')
guido = santa.Person('Guido van Rossum', 'guido@python.org')
Put them into a list:
people = [john, sally, linus, guido]
If any participants have restrictions on who they can give to (say, John and Sally are married and will be getting each other gifts regardless), create a dictionary with the giver as the key and the banned recipients in a list as the value:
# not only are John and Sally married, but Sally hates Linus and will not get him a gift.
restrictions = {john: [sally],
sally: [john, linus]}
Pass these into the function santa.run(person_list, invalid_links=None, *, message='', subject='Secret Santa'). This will match people and send emails. If a match is not found, the program will raise santa.SolvingError. If you haven’t already configured yagmail, it will prompt you for a username and password.
santa.run(people, restrictions, message='Thank you for participating.')
If there are any errors sending emails, they will be printed to the console in the form of a list of tuples of (gifter, recipient). You, the operator, must decide how to handle this.
Options
By default, santa will solve using the 'loop' strategy, which results in a “gifting loop.” As of version 0.2, santa can also solve with the method 'draw', which simulates drawing tickets from a hat. This method will not necessarily result in a loop, but it will be possible for “pairs” of two gifters giving to each other to occur.
To set a solving mode, pass it into santa.run() like so:
santa.run(people, restrictions, solve_mode='loop')
The current list of solving modes is as follows:
'loop' (default)
'draw'
Santa also has options for output modes. By default, it will email recipients. But as of version 0.2, it also has the option to save output to text files in the current working directory. These can be attached to emails and sent without the operator having to find out who is assigned to whom.
To set an output mode, pass it into santa.run() like so:
santa.run(people, restrictions, out_mode='text')
The current list of output modes is as follows:
'email' (default)
'text'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file santa-0.2.2.tar.gz
.
File metadata
- Download URL: santa-0.2.2.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4b9296ddbeec066c2a7feecf284692fa4d758043023b4be9d4cdec2dff12e53 |
|
MD5 | 0180ed8e0e90ceef46c03f7b6d5de0c9 |
|
BLAKE2b-256 | 22e000ead82e76b5910fe38796c2aa99d99d137be7c61340e7122e9bc401d40d |