@@ -63,13 +63,22 @@ def __init__(self, query_parameters):
63
63
# for a given billing group
64
64
group_type = "account_coding" if os .environ .get ("GROUP_TYPE" ) == "account_coding" else "billing_group"
65
65
self .emails_for_billing_groups = defaultdict (set )
66
+ self .names_for_billing_groups = defaultdict (set )
66
67
self .additional_contacts_for_billing_groups = defaultdict (list )
67
68
for account in self .org_accounts :
68
69
self .emails_for_billing_groups [account [group_type ]].add (account ["admin_contact_email" ])
69
-
70
70
additional_contacts = account .get ("additional_contacts" , "" ).split ("/" )
71
71
self .additional_contacts_for_billing_groups [account [group_type ]] = list (set (self .additional_contacts_for_billing_groups [account [group_type ]]).union (set (additional_contacts )))
72
-
72
+ admin_contact_name = account .get ("admin_contact_name" , "Unnamed" ) # Unnamed is the default value
73
+ self .names_for_billing_groups [account [group_type ]].add (admin_contact_name )
74
+ @staticmethod
75
+ def extract_name_from_email (email_address ):
76
+ #p.m@gov.bc.ca P M
77
+ # Assuming email_address is a string like 'firstname.lastname@domain'
78
+ name_part = email_address .split ('@' )[0 ] # Split the email by '@' and take the first part
79
+ name_parts = name_part .split ('.' ) # Split the name part by '.'
80
+ capitalized_name_parts = [part .capitalize () for part in name_parts ] # Capitalize each part
81
+ return ' ' .join (capitalized_name_parts ) # Join the parts into a full name string
73
82
74
83
def create_project_set_lookup (self ):
75
84
project_set_lookup = {}
@@ -105,6 +114,7 @@ def __deliver_reports(self, billing_group_totals):
105
114
logger .info ("Delivering Cloud Consumption Reports..." )
106
115
if os .environ .get ("REPORT_TYPE" ) == "Quarterly" :
107
116
recipient_email = self .query_parameters .get ("recipient_override" )
117
+ recipient_name = self .extract_name_from_email (recipient_email .strip ())
108
118
carbon_copy = self .query_parameters .get ("carbon_copy" )
109
119
cc_email_address = carbon_copy if carbon_copy and carbon_copy != "" else None
110
120
subject = (
@@ -134,6 +144,7 @@ def __deliver_reports(self, billing_group_totals):
134
144
override_email_address = self .query_parameters .get ("recipient_override" )
135
145
if override_email_address and override_email_address != "" :
136
146
recipient_email = override_email_address
147
+ recipient_name = self .extract_name_from_email (override_email_address .strip ())
137
148
# Since we have recepient override, we do not want to send emails to additional contacts
138
149
additional_contacts = []
139
150
else :
@@ -142,6 +153,7 @@ def __deliver_reports(self, billing_group_totals):
142
153
).pop ()
143
154
recipient_email = billing_group_email
144
155
156
+ recipient_name = self .names_for_billing_groups [billing_group ].pop ()
145
157
# Get Additioanl contacts for each Billing Group
146
158
additional_contacts = self .additional_contacts_for_billing_groups [billing_group ]
147
159
additional_contacts = [email for email in additional_contacts if email .strip () != "" ]
@@ -157,14 +169,16 @@ def __deliver_reports(self, billing_group_totals):
157
169
158
170
159
171
subject = (
160
- f"Cloud Consumption Report ${ billing_group_totals .get (billing_group )} for "
161
- f"{ self .query_parameters ['start_date' ].strftime ('%d-%m-%Y' )} to "
172
+ f"Cloud Consumption Report for { billing_group } - "
173
+ f"${ billing_group_totals .get (billing_group )} "
174
+ f"from { self .query_parameters ['start_date' ].strftime ('%d-%m-%Y' )} to "
162
175
f"{ self .query_parameters ['end_date' ].strftime ('%d-%m-%Y' )} ."
163
176
)
164
177
165
178
body_text = jinja_template .render (
166
179
{
167
180
"billing_group_email" : recipient_email ,
181
+ "admin_name" :recipient_name ,
168
182
"start_date" : self .query_parameters .get ("start_date" ),
169
183
"end_date" : self .query_parameters .get ("end_date" ),
170
184
"billing_group_total" : billing_group_totals .get (billing_group ),
0 commit comments