-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPy_class_import.py
54 lines (49 loc) · 1.56 KB
/
Py_class_import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import datetime
class MessageUser():
user_details = []
messages = []
base_message = """Hi {name}!
Thank you for the purchase on {date}.
We hope you are exicted about using it. Just as a
reminder the purcase total was ${total}.
Have a great one!
Team CFE
"""
def add_user(self, name, amount, email=None):
name = name[0].upper() + name[1:].lower()
amount = "%.2f" %(amount)
detail = {
"name": name,
"amount": amount,
}
today = datetime.date.today()
date_text = '{today.month}/{today.day}/{today.year}'.format(today=today)
detail['date'] = date_text
if email is not None: # if email != None
detail["email"] = email
self.user_details.append(detail)
def get_details(self):
return self.user_details
def make_messages(self):
if len(self.user_details) > 0:
for detail in self.get_details():
name = detail["name"]
amount = detail["amount"]
date = detail["date"]
message = self.base_message
new_msg = message.format(
name=name,
date=date,
total=amount
)
self.messages.append(new_msg)
return self.messages
return []
obj = MessageUser()
obj.add_user("Justin", 123.32, email='[email protected]')
obj.add_user("jOhn", 94.23)
obj.add_user("Sean", 93.23)
obj.add_user("Emilee", 193.23)
obj.add_user("Marie", 13.23)
obj.get_details()
obj.make_messages()