Mail Room Madness: Building¶
Description¶
You work in the mail room at a local charity. Part of your job is to write incredibly boring, repetitive emails thanking your donors for their generous gifts. You are tired of doing this over an over again, so you’ve decided to let Python help you out of a jam.
You want to write a small command-line script that can handle some of the tasks associated with this job for you. Here’s a list of the things you want to be able to do:
- The script should have a data structure that holds a list of your donors and a history of the amounts they have donated.
- When run, the script should prompt the user to choose from a menu of 2 actions: ‘Send a Thank You’ or ‘Create a Report’.
- If the user selects ‘Send a Thank You’, prompt for a Full Name.
- If the user types ‘list’, show them a list of the donor names and re-prompt
- If the user types a name not in the list, add that name to the data structure and use it.
- If the user types a name in the list, use it.
- Once a name has been selected, prompt for a donation amount.
- Verify that the amount is in fact a number, and re-prompt if it isn’t.
- Once an amount has been given, add that amount to the donation history of the selected user.
- Finally, use string formatting to compose an email thanking the donor for their generous donation. Print the email to the terminal and return to the original prompt.
You need not persist the new donors when the script quits running.
- If the user (you) selected ‘Create a Report’ Print a list of your donors,
sorted by total historical donation amount.
- Include Donor Name, total donated, number of donations and average donation amount as values in each row.
- Using string formatting, format the output rows as nicely as possible. The end result should be tabular (values in each column should align with those above and below)
- After printing this report, return to the original prompt.
- At any point, the user should be able to quit their current task and return to the original prompt.
- From the original prompt, the user should be able to quit the script cleanly.
Tasks¶
Using all you’ve learned so far, complete your mailroom program. For guidance, use the pseudocode and flow chart you created previously.
- use dicts where appropriate
- see if you can use a dict to switch between the users selections
- Try to use a dict and the .format() method to do the letter as one big template – rather than building up a big string in parts.
- For extra fun, see if you can use a file to preserve the donation list and changes made to it while the program is running.
Begin by creating a new repository called mailroom
in GitHub.
Create the repository with a Python .gitignore
file and a reasonable license (MIT is good).
Clone that repository locally.
Once you have it cloned, immediately create a branch called implementation
.
Do your work on that branch.
Add a setup.py
file that defines your program as a distribution.
This file will allow you to install your program.
Make sure that code you want to distribute to end users is included in the distribution.
- optional:
Use a console script entry point to register your main program entry point. If your program is installed, a user should be able to execute it at the command line:
$ mailroom
Add a tox.ini
file that runs your tests in both Python 2.7 and Python 3.5
Make sure your tests pass in both Python environments.
To run your tests, you should be able simply to run tox:
$ tox
Create whatever functions you require in order to accomplish your tasks. Organize the code in a way that makes the most sense to you. If you want to work entirely in one module, that’s fine. If you’d prefer to create a package with multiple modules, that is also fine.
For each and every function you write, use TDD methods to ensure that you have well-tested code. If you have functions with branching logic, you will need to have more than one test for that function. Remember, each test should be only as complex as it needs to be to test one thing. Your tests are as much a part of this assignment as the code itself. Do not neglect them.
The only exceptions to the testing requirements are functions which require user input. Remember the video you watched and the lessons it taught about clean architecture.
When testing, as well as running your code from the command line, you may want to look into the Faker package. It’s a great library for randomly generating things like names.
As you work, commit early and often. Write commit messages that are clear, concise and meaningful. In your code pairings, switch the driver and navigator roles often.
Submitting Your Work¶
When you are done implementing the entire program and all your tests are passing push your code to github.
Open a pull request from your implementation
branch to the master
branch (which should only contain the README, the .gitignore
and the license)
Copy the URL of that pull request and submit it in Canvas.
Use the comment feature in canvas to submit the following:
- At least one well-formed question about the work you did for this assignment
- At least one comment on what went well
- At least one comment on what was particularly difficult or challenging