-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.py
98 lines (73 loc) · 2.32 KB
/
message.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
from utils import get_emails, logger
class MessageHeader():
def __init__(self, from_email, to_email, subject):
self.from_email = from_email
if "," in to_email:
self.to_email = to_email.split(",")
elif os.path.isfile(to_email):
self.to_email = get_emails(to_email)
else:
self.to_email = [to_email]
self.subject = subject
@property
def emails(self):
"""Get email list
:rtype: list
:returns: List of mail addresses
"""
return self.to_email
class MessageContent():
def __init__(self):
self.message = ""
self.text_color = "white"
self.background = "darkred"
def construct_html_message(self):
"""Prepare the message card
:rtype: str
:returns: HTML for the message body
"""
header_text = ('<!doctype html>'
'<html>'
'<head>'
'<meta content="text/html; charset=UTF-8" http-equiv="content-type">'
'<style>'
'#container {'
'width: 500px;'
'height: 300px;'
f'background-color: {self.background};'
'display: flex;'
'justify-content: center;'
'align-items: center;'
'} '
'.message-border {'
'width: 90%;'
'height: 85%;'
f'border: 2px solid {self.text_color};'
'border-radius: 10px;'
'display: flex;'
'justify-content: center;'
'align-items: center;'
'} '
'.message {'
f'color: {self.text_color};'
'font-size: 1.3rem;'
'line-height: 1.3em;'
'text-align: center;'
'padding-left: 5px;'
'padding-right: 5px;'
'}'
'</style>'
'</head>')
body_text = """<body>
<div id="container">
<div class="message-border">
<p class="message">{message}</p>
</div>
</div>
</body>
</html>
""".format(message=self.message)
message_body = header_text + body_text
logger.debug(f"Message body:\n{message_body}\n")
return message_body