|
| 1 | +import datetime |
| 2 | + |
| 3 | + |
| 4 | +class MessageUser(): |
| 5 | + user_details = [] |
| 6 | + messages = [] |
| 7 | + base_message = """Hi {name}! |
| 8 | +
|
| 9 | +Thank you for the purchase on {date}. |
| 10 | +We hope you are exicted about using it. Just as a |
| 11 | +reminder the purcase total was ${total}. |
| 12 | +Have a great one! |
| 13 | +
|
| 14 | +Team CFE |
| 15 | +""" |
| 16 | + def add_user(self, name, amount, email=None): |
| 17 | + name = name[0].upper() + name[1:].lower() |
| 18 | + amount = "%.2f" %(amount) |
| 19 | + detail = { |
| 20 | + "name": name, |
| 21 | + "amount": amount, |
| 22 | + } |
| 23 | + today = datetime.date.today() |
| 24 | + date_text = '{today.month}/{today.day}/{today.year}'.format(today=today) |
| 25 | + detail['date'] = date_text |
| 26 | + if email is not None: # if email != None |
| 27 | + detail["email"] = email |
| 28 | + self.user_details.append(detail) |
| 29 | + def get_details(self): |
| 30 | + return self.user_details |
| 31 | + def make_messages(self): |
| 32 | + if len(self.user_details) > 0: |
| 33 | + for detail in self.get_details(): |
| 34 | + name = detail["name"] |
| 35 | + amount = detail["amount"] |
| 36 | + date = detail["date"] |
| 37 | + message = self.base_message |
| 38 | + new_msg = message.format( |
| 39 | + name=name, |
| 40 | + date=date, |
| 41 | + total=amount |
| 42 | + ) |
| 43 | + self.messages.append(new_msg) |
| 44 | + return self.messages |
| 45 | + return [] |
| 46 | + |
| 47 | + |
| 48 | +obj = MessageUser() |
| 49 | +obj. add_user( "Justin", 123.32, email='[email protected]') |
| 50 | +obj.add_user("jOhn", 94.23) |
| 51 | +obj.add_user("Sean", 93.23) |
| 52 | +obj.add_user("Emilee", 193.23) |
| 53 | +obj.add_user("Marie", 13.23) |
| 54 | +obj.get_details() |
| 55 | + |
| 56 | +obj.make_messages() |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +default_names = ["Justin", "john", "Emilee", "Jim", "Ron", "Sandra", "veronica", "Whitney"] |
| 63 | +default_amounts = [123.32, 94.23, 124.32, 323.4, 23, 322.122323, 32.4, 99.99] |
| 64 | + |
| 65 | +unf_message = """Hi {name}! |
| 66 | +
|
| 67 | +Thank you for the purchase on {date}. |
| 68 | +We hope you are exicted about using it. Just as a |
| 69 | +reminder the purcase total was ${total}. |
| 70 | +Have a great one! |
| 71 | +
|
| 72 | +Team CFE |
| 73 | +""" |
| 74 | + |
| 75 | + |
| 76 | +def make_messages(names, amounts): |
| 77 | + messages = [] |
| 78 | + if len(names) == len(amounts): |
| 79 | + i = 0 |
| 80 | + today = datetime.date.today() |
| 81 | + text = '{today.month}/{today.day}/{today.year}'.format(today=today) |
| 82 | + for name in names: |
| 83 | + """ |
| 84 | + Here's a simple solution to capitalize |
| 85 | + everyone's name prior to sending |
| 86 | + """ |
| 87 | + name = name[0].upper() + name[1:].lower() |
| 88 | + |
| 89 | + """ |
| 90 | + Did you get the bonus?? |
| 91 | + """ |
| 92 | + |
| 93 | + new_amount = "%.2f" %(amounts[i]) |
| 94 | + new_msg = unf_message.format( |
| 95 | + name=name, |
| 96 | + date=text, |
| 97 | + total=new_amount |
| 98 | + ) |
| 99 | + i += 1 |
| 100 | + print(new_msg) |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +make_messages(default_names, default_amounts) |
0 commit comments