Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW [-1] Mailroom_OO #223

Open
wants to merge 81 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
f9f9d58
"added Readme"
dancornutt Oct 10, 2018
ba3781a
Added typo
dancornutt Oct 10, 2018
dc4ac5d
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
dancornutt Oct 10, 2018
52ffacd
Changed Dir filepath, was in example_students...oops
dancornutt Oct 10, 2018
98812f6
removed accidental file!
dancornutt Oct 13, 2018
c53ee6e
Submitting break_me.py for git practice
dancornutt Oct 15, 2018
7420596
Adding the git ignore file
dancornutt Oct 16, 2018
14b74b0
changed name of git ignore file
dancornutt Oct 16, 2018
27ceb70
added local only folder
dancornutt Oct 17, 2018
5e6caa0
Notes and examples from class.
dancornutt Oct 17, 2018
4647126
added more notes
dancornutt Oct 17, 2018
621fe79
Delete 2018-11-16_Notes.txt
dancornutt Oct 17, 2018
aca0c3c
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
dancornutt Oct 17, 2018
6900410
changed file structure and added session02 modules.
dancornutt Oct 20, 2018
6e40048
Merge branch 'master' of https://github.com/dancornutt/Fall2018-PY210A
dancornutt Oct 20, 2018
3924a66
added assertions for testing.
dancornutt Oct 20, 2018
91fc652
updated print_grid with correct spacing
dancornutt Oct 23, 2018
312ef8d
updated ignore file to ignore local hw folder
dancornutt Oct 23, 2018
7f36102
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
dancornutt Oct 24, 2018
1af302e
Added files for list_lab and slicing lab
dancornutt Oct 27, 2018
fb345aa
Added shebang line and +x modifier
dancornutt Oct 28, 2018
1565996
Finished list_lab, still need to complete bonus if time allows.
dancornutt Oct 28, 2018
1bbb7f4
Finished all series in list lab, still need to do the bonus
dancornutt Oct 28, 2018
74331d3
Finished up slice.py lab
dancornutt Oct 29, 2018
ca93463
Created empty file
dancornutt Oct 29, 2018
4527b07
completed mailroom thankyou, started strformat_lab
dancornutt Oct 30, 2018
631041e
completed mailroom task, working on formatting
dancornutt Oct 30, 2018
1d2571b
progress on the last lab!
dancornutt Oct 30, 2018
d935df4
Finished up the lab for string formatting.
dancornutt Oct 30, 2018
700676a
Mailroom - report now ordered
dancornutt Oct 31, 2018
7f98f02
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
dancornutt Oct 31, 2018
db6cc66
created files, started dict lab
dancornutt Nov 2, 2018
beb8086
completed dict_lab, could update docstring to be more clear
dancornutt Nov 2, 2018
d5d9a45
added file_ex.py for File Exercise in hw
dancornutt Nov 2, 2018
310e57a
Finished dict_lab and file_ex
dancornutt Nov 4, 2018
d305bb0
Changed trigrams to read file and create new edited file
dancornutt Nov 4, 2018
6c5cd44
Of trigram problem, for read/write to work and removing unwanted char…
dancornutt Nov 4, 2018
6d632d6
got trigram working
dancornutt Nov 4, 2018
8cb5948
added initial error handler
dancornutt Nov 6, 2018
a90204b
added new text
dancornutt Nov 6, 2018
f134a0e
added mailroom.py (part2) still in work
dancornutt Nov 7, 2018
4d99367
working on mailroom.py part 2, not finished. Will finish in session05 hw
dancornutt Nov 7, 2018
c003086
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
dancornutt Nov 7, 2018
78df3a9
Finished exceptions_lab.py
dancornutt Nov 8, 2018
4e63712
Finished except_exercise.py
dancornutt Nov 8, 2018
7d44d68
added comprehension_lab.py --in work
dancornutt Nov 9, 2018
f342d86
Started dict_set_lab2.py
dancornutt Nov 10, 2018
afc3eae
Added more functionaltiy for mailroom, with dispatch dict and donatio…
dancornutt Nov 11, 2018
b5d7dbc
Mailroom now has report with dictionary
dancornutt Nov 11, 2018
8a2900e
Mailroom updated for sorted report
dancornutt Nov 11, 2018
29555f5
Mailroom working nicely, basics are complete.
dancornutt Nov 11, 2018
e68ae27
Fixed menu error in Mailroom
dancornutt Nov 12, 2018
5a2e368
removed unneeded functionality from mailroom
dancornutt Nov 13, 2018
d1029c9
Finished unit test labs
dancornutt Nov 18, 2018
27d1d41
added advanced params to mailroom. it's sweet.
dancornutt Nov 19, 2018
eb1a56c
Added unit test file.
dancornutt Nov 20, 2018
6c4c6d0
added functionality of test_mailroom.py
dancornutt Nov 20, 2018
328c353
Added more test_mailroom.py functionality, ran out of time to finish.
dancornutt Nov 20, 2018
cd8538d
Started Session07 html renderer
dancornutt Nov 24, 2018
b2e67c5
On step 4 of HTML parser
dancornutt Nov 27, 2018
bce1cb3
Through step 4 of HTML parser
dancornutt Nov 27, 2018
bb32577
Working on Step 5
dancornutt Nov 27, 2018
039a1bf
On to step 6
dancornutt Nov 27, 2018
55a0f41
Complete with Step 5
dancornutt Nov 27, 2018
0c9c351
Finished Step 6
dancornutt Nov 27, 2018
2fc7e0c
Finished step 7
dancornutt Nov 27, 2018
6575712
Merge branch 'master' into master
dancornutt Nov 28, 2018
7348a63
Halfway through Step 7
dancornutt Nov 28, 2018
ef89656
Working on Step 7 still
dancornutt Nov 28, 2018
a9affd5
added session 08
dancornutt Nov 28, 2018
13418a7
Merge branch 'master' of https://github.com/dancornutt/Fall2018-PY210A
dancornutt Nov 28, 2018
40a1e76
Up through step 7 of hw
dancornutt Dec 1, 2018
ac51b0a
Mostly finished with HW
dancornutt Dec 2, 2018
eb5b1a8
Finished HW
dancornutt Dec 2, 2018
cdbb7ad
Added functionality for +/* ordering
dancornutt Dec 4, 2018
d000bcc
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
dancornutt Dec 5, 2018
226ea72
Working on mailroom_oo
dancornutt Dec 9, 2018
212b4ba
Made progress on YAML input file
dancornutt Dec 12, 2018
7c4338b
added package for mailroom_oo
dancornutt Dec 12, 2018
98a4a30
got mailroom_oo to be functional and use YAML as a input file for the DB
dancornutt Dec 16, 2018
ddd2345
Merge branch 'master' into master
dancornutt Dec 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions students/DanCornutt/session07/html_render.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
# This is the framework for the base class
class Element:
tag = "html"
indent = 4

def __init__(self, content=None, **kwags):
if content:
2 changes: 2 additions & 0 deletions students/DanCornutt/session07/test_html_render.py
Original file line number Diff line number Diff line change
@@ -277,11 +277,13 @@ def test_anchor():


def test_header():
"""a header"""
"""a horizontal rule with an attribute"""
h2 = H(2, "This is a header!")
file_contents = render_result(h2)
print(file_contents)
assert file_contents == '<h2>This is a header!</h2>'

# #####################
# # indentation testing
# # Uncomment for Step 9 -- adding indentation
26 changes: 26 additions & 0 deletions students/DanCornutt/session09/donor_db_DAC.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# !!python/object: __main__.Donor
Fred Jones:
donations:
- 100.01
- 200
- 300
Amy Shumer:
donations:
- 2000
- 4000
- 1000
Billy Bills:
donations:
- 1020
- 20440.55
- 300
Bob Sherlock:
donations:
- 10
- 20
- 30
Tom Johnson:
donations:
- 100
- 200
- 900
30 changes: 30 additions & 0 deletions students/DanCornutt/session09/donor_db_old_DAC.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- fred:
name: Fred Jones
donations:
- 100.01
- 200
- 300
- amy:
name: Amy Shumer
donations:
- 2000
- 4000
- 1000
- billy:
name: Billy Bills
donations:
- 1020
- 20440.55
- 300
- bob:
name: Bob Sherlock
donations:
- 10
- 20
- 30
- tom:
name: Tom Johnson
donations:
- 100
- 200
- 900
210 changes: 210 additions & 0 deletions students/DanCornutt/session09/mailroom_DAC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#!/usr/bin/env python3

"""
mailroom assignment part 2 & 3
"""
from operator import itemgetter
from collections import OrderedDict


DONORS = {
"Fred Jones": [100.01, 200, 300], "Amy Shumer": [2000, 4000, 1000],
"Billy Bills": [1020, 20440.55, 300], "Bob Sherlock": [10, 20, 30],
"Tom Johnson": [100, 200, 900]
}

WELCOME_PROMPT = (
"Welcome to the main menu, please select from the following:\n"
"1 - Send Thank You to a single donor.\n"
"2 - Create a report from Donor history.\n"
"3 - Send letters to all donors.\n"
"4 - Modify Donor Database.\n"
"5 - Quit\n"
)

DATABASE_PROMPT = (
"Welcome to the database menu, please select from the following:\n"
"1 - See list of donors.\n"
"2 - Add new donor or edit existing.\n"
"3 - Quit this menu.\n"
)


def check_donor(name):
"""Returns True if user is in DB. Writes user if write=True
:param1: name of donor
"""
return name in DONORS.keys()

def write_donor(name):
"""Writes thank you email to file"""
text = """Dearest {donor}, \n
We greatly thank you for your recent contribution of ${recent:.2f}.\n
It will go straight to the person who needs it the most, our CEO.\n
Please give more next time.\n
\tLove,\n
\t\t\tThe Team""".format(donor=name, recent=DONORS[name][-1])
with open(name.replace(" ","") + "_thank_you.txt", 'w') as f_out:
f_out.write(text)


def thank_you(donor="", all_users=False):
"""Writes thank you letter to file, if all_users is True write letters for all users in database
"""
if all_users:
for d in DONORS:
write_donor(d)
else:
donor = input("Type Donor Name =>").title()
if check_donor(donor):
write_donor(donor)
else:
print("Sorry I could not find the donor, exiting...")


def donor_db():
"""Editing Donor Menu"""
menu_selection(DATABASE_PROMPT, DATABASE_DISPATCH)


def edit_donor():
answer = input("input donor name=> ").strip().title()
if answer:
add_donation(answer)
else:
print("The name must be letters only, returning...")
thank_you()

def add_donation(donor_name):
"""adds donation to donor records, adds donor if new donor

:param1: donar name
"""
donation = add_money()
if donation:
DONORS.setdefault(donor_name, []).append(donation)
print(
"Thank you {} for your donation of ${:,.2f} dollars!".format(
donor_name, donation)
)


def add_money():
"""Takes input from user, validates donation

:returns: donation amount or None if donation is invalid.
"""
donation = input("Please enter the donor amount larger than 0.01 => $")
try:
if float(donation) < 0.01:
raise ValueError
except ValueError:
print("Donation Error, numbers only. Value must be number greater than 0.01")
return None
else:
return float(donation)


def thank_you_all():
"""Writes thank you email to all users"""
thank_you(all_users=True)


def report():
"""Finds column widths, sorts donors based on amount donated.
:returns: report string
"""
rpt_sheet = []
len_col = OrderedDict({
"n_size": len("Donor Name"),
"t_size" : len("Total Given"),
"ng_size": len("Num Gifts"),
"ag_size": len("Average Gift")
})

for d in DONORS.items():
if len(d[0]) > len_col["n_size"]:
len_col["n_size"] = len(d[0])
if len(str(sum(d[1]))) > len_col["t_size"]:
len_col["Tt_size"] = len(str(sum(d[1])))
if len((d[1])) > len_col["ng_size"]:
len_col["ng_size"] = len((d[1]))
if len(str(sum(d[1])/len(d[1]))) > len_col["ag_size"]:
len_col["ag_size"] = len(str(sum(d[1])/len(d[1])))
rpt_sheet.append((d[0], sum(d[1]), len(d[1]), sum(d[1])/len(d[1])))
rpt_sheet.sort(key=return_total, reverse=True)

sheet = (
"{nm:{mnm}} | {tot:<{mtot}} | {ng:<{mng}} | {ag:<{mag}}\n{header}".format(
nm="Donor Name", mnm=len_col["n_size"],
tot="Total Given", mtot=len_col["t_size"],
ng="Num Gifts", mng=len_col['ng_size'],
ag="Average Gift", mag=len_col["ag_size"],
header=("-" * sum(len_col.values()))
)
)
for d in rpt_sheet:
sheet = sheet + (
"\n{n:{n_size}} |${t:>{t_size},.2f} | {ng:>{ng_size}} |$ {avg_g:<{ag_size},.2f}"
.format(
n=d[0], n_size=len_col['n_size'],
t=d[1], t_size=len_col['t_size'],
ng=d[2], ng_size=len_col['ng_size'],
avg_g=d[3], ag_size=len_col['ag_size']
)
)
return sheet


def make_report():
"""Prints report"""
info = report()
print(info)
print(sheet)

def return_total(elem):
"""sorting function for list"""
return elem[1]


def donor_list():
"""prints donor in dict"""
for k in DONORS:
print(k)


def unknown():
"""Handles unknown user input"""
print("That is not a valid response!")


def quit_menu():
"""Quits menu, returns 'exit menu'. """
print("Quitting this menu now.")
return "exit menu"


def menu_selection(prompt, dispatch_dict):
"""dispatch function for mailroom"""
while True: #this loops forever, until quit is selected
response = input(prompt).strip()
response = response[:1].lower()
if dispatch_dict.get(response, unknown)() == "exit menu":
break

MAIN_DISPATCH = {
"1": thank_you,
"2": make_report,
"3": thank_you_all,
"4": donor_db,
"5": quit_menu,
}

DATABASE_DISPATCH = {
"1": donor_list,
"2": edit_donor,
"3": quit_menu
}

if __name__ == "__main__":
menu_selection(WELCOME_PROMPT, MAIN_DISPATCH)
100 changes: 100 additions & 0 deletions students/DanCornutt/session09/mailroom_oo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!usr/bin/#!/usr/bin/env python
"""mailroom_oo module contains data objects donor and donor_collection to handle
all required operations for the mailroom script. User inputs are handled
elsewhere."""

# └── mailroom_oo
# ├── __init__.py - empty for init
# ├── cli_main.py - user interface file
# ├── donor_models.py - data file
# └── test_mailroom_oo.py - test file

import os
import yaml


class Donor:
"""Donor class handles all data, opperations, and attributes needed for
donors."""
def __init__(self, name, donations=None):
self.name = name
if donations:
self.donations = donations
else:
self.donations = []

def add_donation(self, donation):
"""Adds donation from donor to donor DB
parma1: donation (number)"""
self.donations.append(donation)

@property
def num_donations(self):
"""Returns number of donations."""
return len(self.donations)

@property
def donor_name(self):
"""Returns name of donor."""
return self.name

@property
def last_donation(self):
"""Returns last donation or None if no donations."""
if self.num_donations:
return self.donations[-1]
else: return None

@property
def avg_donation(self):
"""Returns average donor donation or None if no donations."""
if self.num_donations:
return self.sum_donations/self.num_donations
else: return None

@property
def sum_donations(self):
"""Returns total amount donated."""
return sum(self.donations)

def write_letter(self):
"""Writes thank you letter for donor's last donation. Returns string."""
text = """Dearest {donor},
We greatly thank you for your recent contribution of ${recent:.2f}.
It will go straight to the person who needs it the most, our CEO.
Please give more next time.
Love,
The Team""".format(donor=self.name, recent=self.last_donation)
return text


#report - sort key needed
#thank you letters - return list of strings
#check donor if needed elsewhere

#user interface code for input and prints

class Donor_Collection:
def __init__(self):
self.name = "donor_db_object"
self.db = {}
data = yaml.load(open("donor_db.yaml"))

for k,v in data.items():
self.add_donor(k,v)


def add_donor(self, name, donations=None):
"""Adds donor to database."""
print(name, donations)
self.db[name] = Donor(name, donations['donations'])


def list_donors(self):
"""Returns list of all donors in database."""
donors_str = ""
for person in self.db.keys():
print(person)
donors_str.join(person + "\n")

donors = Donor_Collection()
1 change: 1 addition & 0 deletions students/DanCornutt/session09/mailroom_oo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
Loading