Skip to content

Commit 258c9b4

Browse files
Merge pull request #24 from abibat-adesina/master
having license plate as part of the subject
2 parents 020158c + 937fd51 commit 258c9b4

File tree

3 files changed

+195
-159
lines changed

3 files changed

+195
-159
lines changed

billing-report-utility/BillingManager.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,22 @@ def __init__(self, query_parameters):
6363
# for a given billing group
6464
group_type = "account_coding" if os.environ.get("GROUP_TYPE") == "account_coding" else "billing_group"
6565
self.emails_for_billing_groups = defaultdict(set)
66+
self.names_for_billing_groups = defaultdict(set)
6667
self.additional_contacts_for_billing_groups = defaultdict(list)
6768
for account in self.org_accounts:
6869
self.emails_for_billing_groups[account[group_type]].add(account["admin_contact_email"])
69-
7070
additional_contacts = account.get("additional_contacts", "").split("/")
7171
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
7382

7483
def create_project_set_lookup(self):
7584
project_set_lookup = {}
@@ -105,6 +114,7 @@ def __deliver_reports(self, billing_group_totals):
105114
logger.info("Delivering Cloud Consumption Reports...")
106115
if os.environ.get("REPORT_TYPE") == "Quarterly":
107116
recipient_email = self.query_parameters.get("recipient_override")
117+
recipient_name = self.extract_name_from_email(recipient_email.strip())
108118
carbon_copy = self.query_parameters.get("carbon_copy")
109119
cc_email_address = carbon_copy if carbon_copy and carbon_copy != "" else None
110120
subject = (
@@ -134,6 +144,7 @@ def __deliver_reports(self, billing_group_totals):
134144
override_email_address = self.query_parameters.get("recipient_override")
135145
if override_email_address and override_email_address != "":
136146
recipient_email = override_email_address
147+
recipient_name = self.extract_name_from_email(override_email_address.strip())
137148
# Since we have recepient override, we do not want to send emails to additional contacts
138149
additional_contacts = []
139150
else:
@@ -142,6 +153,7 @@ def __deliver_reports(self, billing_group_totals):
142153
).pop()
143154
recipient_email = billing_group_email
144155

156+
recipient_name = self.names_for_billing_groups[billing_group].pop()
145157
# Get Additioanl contacts for each Billing Group
146158
additional_contacts = self.additional_contacts_for_billing_groups[billing_group]
147159
additional_contacts = [email for email in additional_contacts if email.strip() != ""]
@@ -157,14 +169,16 @@ def __deliver_reports(self, billing_group_totals):
157169

158170

159171
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 "
162175
f"{self.query_parameters['end_date'].strftime('%d-%m-%Y')}."
163176
)
164177

165178
body_text = jinja_template.render(
166179
{
167180
"billing_group_email": recipient_email,
181+
"admin_name":recipient_name,
168182
"start_date": self.query_parameters.get("start_date"),
169183
"end_date": self.query_parameters.get("end_date"),
170184
"billing_group_total": billing_group_totals.get(billing_group),

billing-report-utility/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ pandas==1.4.2
88
numpy==1.22.4
99
jinja2==3.1.1
1010
openpyxl==3.0.10
11-
urllib3==1.26.4
11+
urllib3==1.26.4

0 commit comments

Comments
 (0)