Skip to content

Commit

Permalink
Merge pull request #132 from networktocode/gfm-telstra-alternate-canc…
Browse files Browse the repository at this point in the history
…elled

Handle alternate 'has been cancelled' text in Telstra notifications
  • Loading branch information
glennmatthews authored Dec 17, 2021
2 parents 2b0c3e4 + 766a27d commit f6294cd
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 6 deletions.
13 changes: 7 additions & 6 deletions circuit_maintenance_parser/parsers/telstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ def parse_html(self, soup):
self.parse_tables(soup.find_all("table"), data)
return [data]

def parse_tables(self, tables: ResultSet, data: Dict):
def parse_tables(self, tables: ResultSet, data: Dict): # pylint: disable=too-many-locals
"""Parse Table tag."""
for table in tables:
for td_element in table.find_all("td"):
# TODO: We should find a more consistent way to parse the status of a maintenance note
if "maintenance has been scheduled" in td_element.text.lower():
td_text = td_element.text.lower()
if "maintenance has been scheduled" in td_text:
data["status"] = Status("CONFIRMED")
elif "this is a reminder notification to notify that a planned maintenance" in td_element.text.lower():
elif "this is a reminder notification to notify that a planned maintenance" in td_text:
data["status"] = Status("CONFIRMED")
elif "has been completed" in td_element.text.lower():
elif "has been completed" in td_text:
data["status"] = Status("COMPLETED")
elif "has been amended" in td_element.text.lower():
elif "has been amended" in td_text:
data["status"] = Status("RE-SCHEDULED")
elif "has been withdrawn" in td_element.text.lower():
elif "has been withdrawn" in td_text or "has been cancelled" in td_text:
data["status"] = Status("CANCELLED")
else:
continue
Expand Down
207 changes: 207 additions & 0 deletions tests/unit/data/telstra/telstra7.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8">
<title>Maintenance - Telstra</title>
<style type=3D"text/css">
outlook a {
padding: 0;
}
body {
background: #FFF;
width: 100% !important;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
}
td { }
p { margin-top: 0.7em; margin-bottom: 0.7em; }
ul { margin: 0; padding: 0 0 0 15px; list-style-type: disc; }
li { padding: 0px; margin: 0 0 0.4em; }
a { color: #B32034; text-decoration: none; }
img { border: 0; }
hr { clear: both; background-color: #CCC; border: none; color: #CCC; height=
: 1px; margin: 1em 0; }
</style>
</head>

<body style=3D"background: #FFF;width: 100% !important;-webkit-text-size-ad=
just: 100%;-ms-text-size-adjust: 100%;margin: 0;padding: 0;font-family: Ari=
al, Helvetica, sans-serif">
<table cellpadding=3D"0" cellspacing=3D"0" border=3D"0" width=3D"600" align=
=3D"center" style=3D"margin: 0 auto;padding: 0;width: 600px !important;line=
-height: 100% !important;background: #FFF">
<tr>
<td>
<table width=3D"600" border=3D"0" cellpadding=3D"15" cellspacing=3D"0=
" style=3D"background: #EEE">
<tr>
<td><table cellpadding=3D"0" cellspacing=3D"0" border=3D"0" align=
=3D"center" width=3D"570" style=3D"background: #FFF;width: 570px;margin: 0 =
auto">
<td valign=3D"top"><img src=3D"https://www.telstraglobal.com/upload_fil=
es/banner_notification_OM.png" alt=3D"Telstra" width=3D"570" height=3D"180"=
border=3D"0" style=3D"border: 0; display: block;"/></td>
<tr><td>
<table width=3D510 border=3D0 bordercolor=3Dred cellspacing=3D"5" =
align=3D"center" >
<tr style=3D"font-family: Arial, Helvetica, sans-serif; li=
ne-height: 1.1; font-size:24px; font-weight:bold;color: #B32034; ">
<td style=3D'background: #FFF;' height=3D15>Planned Maint=
enance Cancellation</td>
</tr>
<!--by reejan-->
<tr style=3D"font-family: Arial, Helvetica, sans-serif; line-heigh=
t: 1.1; font-size: 16px; font-weight:bold;color: #B32034; ">
<td style=3D'background: #FFF;' height=3D15>Service Impacti=
ng</td>
</tr>
<tr style=3D"font-family: Arial, Helvetica, sans-serif; lin=
e-height: 1.1; font-size: 12px; color: #B32034; ">
<td style=3D'background: #FFF;' height=3D25>Planned Maint=
enance has been cancelled - Please be advised this work was cancelled due t=
o an equipment issue the prevented the work from being completed .</td>
</tr>
</table>
</td></tr>
</tr>
<td valign=3D"top" style=3D"padding: 0 0 30px;">
<table width=3D"510" border=3D"0" align=3D"center" cellpadding=3D"0" ce=
llspacing=3D"0">
<tr>
<td width=3D"510" colspan=3D"2">
<table width=3D"100%" border=3D"0" cellspacing=3D"2" =
style=3D"font-family: Arial, Helvetica, sans-serif; line-height: 1.1; font-=
size: 11px; color: #000000;">
<br/>
<tr>
<th width=3D"37%" align=3D"left" valign=3D"top" s=
tyle=3D" font-size: 12px; font-weight: bold;"></th>
<td width=3D"63%" valign=3D"top" ></td>
</tr>
<tr>
<th width=3D"37%" align=3D"left" valign=3D"top" s=
tyle=3D" font-size: 12px; font-weight: bold;">To: </th>
<td width=3D"63%" valign=3D"top" >Customer Name</td>
</tr>
<tr>
<th align=3D"left" valign=3D"top" style=3D"f=
ont-size: 12px; font-weight: bold;">Attention: </th>
<td valign=3D"top" style=3D"max-width: 100px; wor=
d-break: break-all;">jhamie villaroman ,amir,jason,chris,nicole ho,donna tu=
rner,rd notices,noc</td>
</tr>
<tr><td width=3D25>&nbsp;</td></tr>
<tr>
<th align=3D"left" valign=3D"top" style=3D"font-s=
ize: 12px; font-weight: bold;">Email :</th>
<td valign=3D"top" style=3D"max-width: 100px; wor=
d-break: break-all;text-decoration:none;"><font style=3D"display: none">@</=
font>[email protected],[email protected],[email protected],=
[email protected],[email protected],[email protected],r=
[email protected],[email protected]</td>
</tr>
<tr><td width=3D25>&nbsp;</td></tr>
<tr>
<th align=3D"left" valign=3D"top" style=3D"font-s=
ize: 12px; font-weight: bold;">Change Reference: </th>
<td valign=3D"top" >PN123456</td>
</tr>
<tr><td width=3D25>&nbsp;</td></tr>
<tr>
<th align=3D"left" valign=3D"top" style=3D"font-s=
ize: 12px; font-weight: bold;">Maintenance Window: </th>
<td valign=3D"top" >13-Dec-2021 12:00:00(UTC) to =
13-Dec-2021 13:29:00(UTC)</td>
</tr>
<tr>
<th align=3D"left" valign=3D"top" style=3D"font-s=
ize: 12px; font-weight: bold;">Expected Impact: </th>
<td valign=3D"top" >1 hour 29 minutes outage with=
in the change window</td>
</tr>
<tr><td width=3D25>&nbsp;</td></tr>
<tr colspan=3D2>
<th align=3D"left" valign=3D"top" style=3D"font-s=
ize: 12px; font-weight: bold;">Maintenance Details:</th>
</tr>
<tr><td width=3D25>&nbsp;</td></tr>
<tr>
<td align=3D"left" colspan=3D"2" valign=3D"top" s=
tyle=3D"font-size: 12px; ">Telstra Corporation Essential Change Notificatio=
n - CMART 3513026</td>

</tr>
<tr><td width=3D25>&nbsp;</td></tr>
<tr>
<td align=3D"left" colspan=3D"2" valign=3D"top" s=
tyle=3D"font-size: 12px; ">Telstra Corporation will implement maintenance w=
ork in Australia due to planned hardware replacement work.
Your service(s) may experience a break to service during the change window.
***At this current time, your link will be down during this maintenance and=
current cable fault AAG Segment 1i (Hongkong -BU4). Please contact our ser=
vice desk [[email protected]] if necessary***</td>

</tr>
<tr><td width=3D25>&nbsp;</td></tr>
<tr>
<th align=3D"left" valign=3D"top" style=3D"font-s=
ize: 12px; font-weight: bold;">Service(s) Impacted:</th>
<td valign=3D"top" >SNG SYD EPL 9875643<br></td>
</tr>
<tr>
<td width=3D25>&nbsp;</td>
</tr>
<tr>
<td colspan=3D"2"align=3D"left" valign=3D"top" =
style=3D"color: #000000;font-size: 12px; "> <a href=3D"mailto:[email protected]=
stra.com?subject=3DQuery- Telstra Planned Maintenance - Service Impacting -=
PN123456"
style=3D"color: #FF7F50;"><u>Click here</u></a> If you have any que=
stions, comments or concerns regarding this maintenance activity or telepho=
ne Global 800: +800 8448 8888* or Direct: +852 3192 7420 </td>

</tr>
<tr>
<td width=3D25>&nbsp;</td>
</tr>
<tr>
<td colspan=3D"2"align=3D"left" valign=3D"top" style=3D"color: #00=
0000; font-size: 12px; "><a href=3D"https://connectapp.telstra.com/"
style=3D"color: #FF7F50;"><u>Click here</u></a> for immediate infor=
mation on planned maintenance or viewing your historical planned maintenanc=
e tickets details via our Telstra Connect Portal using your email ID as log=
in.</td>
</tr>
<tr>
<td width=3D25>&nbsp;</td>
</tr>
<tr>
<td colspan=3D"2"align=3D"left" valign=3D"top" s=
tyle=3D"color: #000000; font-size: 12px; ">
<a href=3D"mailto:[email protected]?subject=3DUpdate contact de=
tails- Telstra Planned Maintenance - Service Impacting - PN123456
&body=3DHi Change Management team,%0D%0A %0D%0AI would like to updat=
e my personal contact information as below:%0D%0A Email id:%0D%0A =
Contact number:"
style=3D"color: #FF7F50;"><u>Click here</u> </a> to email us about a=
ny updates to your contact details or requesting access to Telstra Connect =
Portal.
</td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>

</td>
</tr>
</table>
</body>
</html>
16 changes: 16 additions & 0 deletions tests/unit/data/telstra/telstra7_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"account": "Customer Name",
"circuits": [
{
"circuit_id": "SNG SYD EPL 9875643",
"impact": "OUTAGE"
}
],
"end": 1639402140,
"maintenance_id": "PN123456",
"start": 1639396800,
"status": "CANCELLED",
"summary": "Telstra Corporation Essential Change Notification - CMART 3513026. Telstra Corporation will implement maintenance work in Australia due to planned hardware replacement work.\r\nYour service(s) may experience a break to service during the change window.\r\n***At this current time, your link will be down during this maintenance and current cable fault AAG Segment 1i (Hongkong -BU4). Please contact our service desk [[email protected]] if necessary***"
}
]
5 changes: 5 additions & 0 deletions tests/unit/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
Path(dir_path, "data", "telstra", "telstra6.html"),
Path(dir_path, "data", "telstra", "telstra6_result.json"),
),
(
HtmlParserTelstra1,
Path(dir_path, "data", "telstra", "telstra7.html"),
Path(dir_path, "data", "telstra", "telstra7_result.json"),
),
# Turkcell
(
HtmlParserTurkcell1,
Expand Down

0 comments on commit f6294cd

Please sign in to comment.