Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DEFAULT_EMAIL_TYPE = "text"
- DEFAULT_RECIPIENT = "alecmunro@gmale.com"
- DEFAULT_SUBJECT = "Good news, everyone!"
- class EmailReporter(object):
- email_type = DEFAULT_EMAIL_TYPE
- def send_report(self, settings):
- data = self.collect_data()
- body = self.create_body(data)
- self.send_email(data["recipient"], settings["sender"],
- self.email_type, data["subject"], body)
- def send_email(self, to, from, subject, body,
- type=DEFAULT_EMAIL_TYPE):
- ...
- def collect_data(self)
- return {"recipient": DEFAULT_RECIPIENT,
- "subject": DEFAULT_SUBJECT}
- def create_body(self, data):
- return "Bad news, everyone."
- class HTMLEmailReporter(EmailReporter):
- email_type = "html"
- def collect_data(self):
- base_data = super(HTMLEmailReporter, self)\
- .collect_data()
- base_data.update({
- "analysis": "complete",
- "recommendation": "immediate termination"
- }
- return base_data
- def create_body(self, data):
- return """<html><body>
- Our analysis process is <em>{analysis}</em>.<br />
- Based on this, we are recommending {recommendation}
- of the project.</body></html>""".format(**data)
- class TextEmailReporter(EmailReporter):
- def collect_data(self):
- base_data = super(TextEmailReporter, self)\
- .collect_data()
- base_data.update({
- "analysis": "complete",
- "steps": ["Buy Ferret Ranch", "???", "Profit!"]
- }
- return base_data
- def create_body(self, data):
- body = "Our analysis process is {analysis}.\n"\
- "We determined that the process was as follows:\n"\
- .format(**data)
- for i, step in enumerate(data["steps"]):
- body += "{0}. {1}".format(i+1, step)
- return body
Add Comment
Please, Sign In to add comment