Guest User

Untitled

a guest
Jan 22nd, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. DEFAULT_EMAIL_TYPE = "text"
  2. DEFAULT_RECIPIENT = "alecmunro@gmale.com"
  3. DEFAULT_SUBJECT = "Good news, everyone!"
  4.  
  5. class EmailReporter(object):
  6.  
  7. email_type = DEFAULT_EMAIL_TYPE
  8.  
  9. def send_report(self, settings):
  10. data = self.collect_data()
  11. body = self.create_body(data)
  12. self.send_email(data["recipient"], settings["sender"],
  13. self.email_type, data["subject"], body)
  14.  
  15. def send_email(self, to, from, subject, body,
  16. type=DEFAULT_EMAIL_TYPE):
  17. ...
  18.  
  19. def collect_data(self)
  20. return {"recipient": DEFAULT_RECIPIENT,
  21. "subject": DEFAULT_SUBJECT}
  22.  
  23. def create_body(self, data):
  24. return "Bad news, everyone."
  25.  
  26.  
  27. class HTMLEmailReporter(EmailReporter):
  28.  
  29. email_type = "html"
  30.  
  31. def collect_data(self):
  32. base_data = super(HTMLEmailReporter, self)\
  33. .collect_data()
  34. base_data.update({
  35. "analysis": "complete",
  36. "recommendation": "immediate termination"
  37. }
  38. return base_data
  39.  
  40. def create_body(self, data):
  41. return """<html><body>
  42. Our analysis process is <em>{analysis}</em>.<br />
  43. Based on this, we are recommending {recommendation}
  44. of the project.</body></html>""".format(**data)
  45.  
  46.  
  47. class TextEmailReporter(EmailReporter):
  48.  
  49. def collect_data(self):
  50. base_data = super(TextEmailReporter, self)\
  51. .collect_data()
  52. base_data.update({
  53. "analysis": "complete",
  54. "steps": ["Buy Ferret Ranch", "???", "Profit!"]
  55. }
  56. return base_data
  57.  
  58. def create_body(self, data):
  59. body = "Our analysis process is {analysis}.\n"\
  60. "We determined that the process was as follows:\n"\
  61. .format(**data)
  62. for i, step in enumerate(data["steps"]):
  63. body += "{0}. {1}".format(i+1, step)
  64. return body
Add Comment
Please, Sign In to add comment