-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (48 loc) · 1.58 KB
/
Copy pathmain.py
File metadata and controls
57 lines (48 loc) · 1.58 KB
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
from dsc.cmdline import parse_cmdline
from dsc.issue import GithubIssue
from dsc.params import SendEmailParams
from dsc.invoice import InvoiceHTMLParser
from dsc.email import Email, EmailTemplate
import os
import sys
TEMPLATE_FOLDER = os.path.join(os.path.dirname(__file__), 'template')
def main():
"""Execute modules to send order update email to DSC users."""
parser = InvoiceHTMLParser()
args = parse_cmdline()
issue = GithubIssue(
token=args.token,
repository=args.repository,
organization=args.organization
)
parser.feed(issue.html(args.issueid))
file = os.path.join(TEMPLATE_FOLDER, 'update_template.html')
try:
os.path.exists(file) is True
except FileNotFoundError as fnf_error:
print(fnf_error)
sys.exit("Email update template was not found.")
else:
try:
with open(file, 'r') as f:
content = f.read()
except RuntimeError as error:
print(error)
sys.exit("Could not read order update template file.")
template = EmailTemplate(message=content)
email = Email(endpoint=args.endpoint, api_key=args.apikey)
email.send(SendEmailParams(
sender=args.sender,
to=parser.get_shipping_email(),
subject=template.generate_subject(
issue_id=parser.get_order_id(),
label=args.label
),
content=template.generate_content(
user=parser.get_user_name(),
label=args.label,
issue_id=parser.get_order_id()
)
))
if __name__ == "__main__":
main()