-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescriptor2.py
45 lines (34 loc) · 964 Bytes
/
descriptor2.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
from bs4 import BeautifulSoup
class HTMLEmail:
_subject = None
_body = None
_body_plain = None
@property
def subject(self):
return self._subject
@subject.setter
def subject(self, text):
soup = BeautifulSoup(text, 'html.parser')
self._subject = soup.text
@property
def body(self):
return self._body
@body.setter
def body(self, text):
soup = BeautifulSoup(text, 'html.parser')
self._body = soup
@property
def body_plain(self):
return self._body_plain
@body_plain.setter
def body_plain(self, text):
soup = BeautifulSoup(text, 'html.parser')
self._body_plain = soup.text
html = "<p><b>Wow!<b></p><p>A great email from Dan.</p>"
email = HTMLEmail()
email.subject = 'An email from Dan'
email.body = html
email.body_plain = html
print('subject:', email.subject)
print('body: ', email.body)
print('plain: ', email.body_plain)