Skip to content

Commit ffd24f5

Browse files
authored
Tata parser (#297)
* add tata parser * add tata parser unit tests * fix bs4.element import-untyped and _parse_time method return-value * correct black code formatting * ignore pylint c0104 disallowed-name in circuit_maintenance_parser/parsers/tata.py * add tata parser in README.md * avoid computing lower() every time
1 parent 82efe55 commit ffd24f5

36 files changed

+1418
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ By default, there is a `GenericProvider` that supports a `SimpleProcessor` using
8484
- Netflix (AS2906 only)
8585
- Seaborn
8686
- Sparkle
87+
- Tata
8788
- Telstra (\*)
8889
- Turkcell
8990
- Verizon

circuit_maintenance_parser/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
PacketFabric,
2929
Seaborn,
3030
Sparkle,
31+
Tata,
3132
Telia,
3233
Telstra,
3334
Turkcell,
@@ -59,6 +60,7 @@
5960
PacketFabric,
6061
Seaborn,
6162
Sparkle,
63+
Tata,
6264
Telia,
6365
Telstra,
6466
Turkcell,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# pylint: disable=disallowed-name
2+
"""Circuit maintenance parser for Tata Email notifications."""
3+
from typing import List, Dict, Any
4+
from datetime import datetime
5+
6+
from bs4.element import ResultSet # type: ignore
7+
from circuit_maintenance_parser.output import Impact, Status
8+
from circuit_maintenance_parser.parser import Html, EmailSubjectParser
9+
10+
11+
class HtmlParserTata(Html):
12+
"""Custom Parser for HTML portion of Tata circuit maintenance notifications."""
13+
14+
def parse_html(self, soup: ResultSet) -> List[Dict]:
15+
"""Parse Tata circuit maintenance email."""
16+
prev: str = ""
17+
data: Dict[str, Any] = {
18+
"account": "N/A",
19+
"circuits": [],
20+
"organizer": soup.select("a[href^=mailto]")[0].text.strip(),
21+
}
22+
for span in soup.find_all("span"):
23+
curr = span.text.strip()
24+
if curr != prev:
25+
prev_lower = prev.lower()
26+
if prev_lower == "ticket reference - tcl":
27+
data["maintenance_id"] = curr
28+
elif prev_lower == "service id":
29+
for circuit in curr.split(","):
30+
data["circuits"].append(
31+
{
32+
"circuit_id": circuit.strip(),
33+
"impact": Impact.OUTAGE,
34+
}
35+
)
36+
elif prev_lower in ("activity window (gmt)", "revised activity window (gmt)"):
37+
start_end = curr.split("to")
38+
data["start"] = self._parse_time(start_end[0])
39+
data["end"] = self._parse_time(start_end[1])
40+
elif "extended up to time window" in prev_lower:
41+
if "gmt" in curr.lower():
42+
data["end"] = self._parse_time(curr)
43+
prev = span.text.strip()
44+
45+
return [data]
46+
47+
@staticmethod
48+
def _parse_time(string: str) -> int:
49+
"""Convert YYYY-MM-DD HH:MM:SS GMT to epoch."""
50+
return int((datetime.strptime(string.strip(), "%Y-%m-%d %H:%M:%S GMT") - datetime(1970, 1, 1)).total_seconds())
51+
52+
53+
class SubjectParserTata(EmailSubjectParser):
54+
"""Custom Parser for Email subject of Tata circuit maintenance notifications."""
55+
56+
def parse_subject(self, subject: str) -> List[Dict]:
57+
"""Parse Tata Email subject for summary and status."""
58+
data: Dict[str, Any] = {"summary": subject.strip().replace("\n", "")}
59+
subject_lower = subject.lower()
60+
if "completion" in subject_lower:
61+
data["status"] = Status.COMPLETED
62+
elif "reschedule" in subject_lower or "extension" in subject_lower:
63+
data["status"] = Status.RE_SCHEDULED
64+
elif "reminder" in subject_lower:
65+
data["status"] = Status.CONFIRMED
66+
elif "cancellation" in subject_lower:
67+
data["status"] = Status.CANCELLED
68+
else:
69+
data["status"] = Status.CONFIRMED
70+
71+
return [data]

circuit_maintenance_parser/provider.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SubjectParserSeaborn2,
3838
)
3939
from circuit_maintenance_parser.parsers.sparkle import HtmlParserSparkle1
40+
from circuit_maintenance_parser.parsers.tata import HtmlParserTata, SubjectParserTata
4041
from circuit_maintenance_parser.parsers.telstra import HtmlParserTelstra1, HtmlParserTelstra2
4142
from circuit_maintenance_parser.parsers.turkcell import HtmlParserTurkcell1
4243
from circuit_maintenance_parser.parsers.verizon import HtmlParserVerizon1
@@ -428,6 +429,19 @@ class Sparkle(GenericProvider):
428429
_default_organizer = PrivateAttr("[email protected]")
429430

430431

432+
class Tata(GenericProvider):
433+
"""Tata provider custom class."""
434+
435+
_include_filter = PrivateAttr({EMAIL_HEADER_SUBJECT: ["Planned Work Notification"]})
436+
437+
_processors: List[GenericProcessor] = PrivateAttr(
438+
[
439+
CombinedProcessor(data_parsers=[HtmlParserTata, SubjectParserTata, EmailDateParser]),
440+
]
441+
)
442+
_default_organizer = PrivateAttr("[email protected]")
443+
444+
431445
class Telia(Arelion):
432446
"""Telia provider custom class."""
433447

tests/unit/data/tata/tata_body.html

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<html><head>
2+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
3+
</head>
4+
<body>
5+
<div style="background-color:#FFEB9C; width:100%; padding:2pt; font-size:10pt; line-height:12pt; font-family:'Calibri'; color:Black; text-align: left;">
6+
<span style="color:#9C6500; font-weight:bold;">CAUTION:</span> This email has been sent from an external source. Do not click links, open attachments, or provide sensitive business information unless you can verify the sender’s legitimacy.
7+
</div>
8+
<br>
9+
<div>
10+
<p></p>
11+
<p></p>
12+
<p></p>
13+
<p><span style="color: #000000; font-size: 10pt; font-family: tahoma, arial, helvetica, sans-serif;">Dear&nbsp;Customer,</span></p>
14+
<p>&nbsp;</p>
15+
<p><span style="color: #000000; font-size: 10pt; font-family: tahoma, arial, helvetica, sans-serif;">Tata Communication is in receipt of maintenance activity. The details of maintenance activity are as below. Your below mentioned service would experience an
16+
outage of “8 Days 23 Hours 58 Minutes” during the activity window.</span></p>
17+
<p>&nbsp;</p>
18+
<table style="height: 42px; border-color: #000000;" border="0" width="623" cellspacing="0">
19+
<tbody>
20+
<tr style="background-color: #4b85c5;">
21+
<td style="border: none; text-align: left; padding-left: 5px;"><span style="font-size: 11pt; color: #ffffff; font-family: helvetica;"><strong>TATA COMMUNICATIONS</strong></span></td>
22+
<td style="border: 0.5px #bbbbbb;">&nbsp;<img style="align: baseline;" title="" src="cid:[email protected]" alt="" width="44" height="38" align="right" border="" hspace="10" vspace=""></td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
<table style="height: 38px; border-color: #000000;" border="1" width="620" cellspacing="0">
27+
<tbody>
28+
<tr>
29+
<td style="background-color: #4b85c5;" colspan="2"><span style="color: #ffffff; font-family: arial, helvetica, sans-serif; font-size: 12pt;">&nbsp;Planned Work Notification</span></td>
30+
</tr>
31+
<tr>
32+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">Ticket Reference - TCL</span></strong></span></td>
33+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">CHGP0123456</span></td>
34+
</tr>
35+
<tr>
36+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">Service ID</span></strong></span></td>
37+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">A012345678901234567, B012345678901234567</span></td>
38+
</tr>
39+
<tr>
40+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">NIMS ID</span></strong></span></td>
41+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">F0123-45678-901, F0123-45678-901</span></td>
42+
</tr>
43+
<tr>
44+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Maintenance Type</span></strong></strong></span></td>
45+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Normal</span></td>
46+
</tr>
47+
<tr>
48+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Activity Status</span></strong></strong></span></td>
49+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Scheduled</span></td>
50+
</tr>
51+
<tr>
52+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Execution Owner</span></strong></strong></span></td>
53+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">International Cables</span></td>
54+
</tr>
55+
<tr>
56+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Location of activity</span></strong></strong></span></td>
57+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Mumbai</span></td>
58+
</tr>
59+
<tr>
60+
<td style="background-color: #4b85c5;" colspan="2">&nbsp;</td>
61+
</tr>
62+
<tr>
63+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Activity Window (IST)</span></strong></strong></span></td>
64+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">2024-12-22 05:31:00 IST to 2024-12-31 05:29:00 IST</span></td>
65+
</tr>
66+
<tr>
67+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Activity Window (GMT)</span></strong></strong></span></td>
68+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">2024-12-22 00:01:00 GMT to 2024-12-30 23:59:00 GMT</span></td>
69+
</tr>
70+
<tr>
71+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Expected Impact Duration(DD:HH:MM) :</span></strong></strong></span></td>
72+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">8 Days 23 Hours 58 Minutes</span></td>
73+
</tr>
74+
<tr>
75+
<td style="background-color: #4b85c5;" colspan="2">&nbsp;</td>
76+
</tr>
77+
<tr>
78+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">Activity Description</span></strong></span></td>
79+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Planned activity for shunt fault repair of Seg 11 near Mumbai in TGNEA network.</span></td>
80+
</tr>
81+
<tr>
82+
<td colspan="2">
83+
<p><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">We request you to reschedule sensitive operations at your end accordingly.<br>
84+
We apologize for any inconvenience due to this event and resulting downtime.<br>
85+
If you have any queries with respect to this activity, feel free to contact us on the coordinates mentioned below:<br>
86+
Mail ID :<a href="mailto:[email protected]">[email protected]</a><br>
87+
Contact Number : + 91 20 6614 4444 &amp; Toll Free no: 1-8002660660<br>
88+
We look forward to your co-operation and a long term synergic association.<br>
89+
Best Regards,<br>
90+
Customer Service<br>
91+
TATA COMMUNICATIONS</span></p>
92+
</td>
93+
</tr>
94+
</tbody>
95+
</table>
96+
<p>&nbsp;</p>
97+
<div>&nbsp;</div>
98+
<div style="display:inline">Ref:MSGTCL000142929801</div>
99+
</div>
100+
</body>
101+
</html>
102+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"account": "N/A",
4+
"circuits": [
5+
{
6+
"circuit_id": "A012345678901234567",
7+
"impact": "OUTAGE"
8+
},
9+
{
10+
"circuit_id": "B012345678901234567",
11+
"impact": "OUTAGE"
12+
}
13+
],
14+
"end": 1735603140,
15+
"maintenance_id": "CHGP0123456",
16+
"organizer": "[email protected]",
17+
"start": 1734825660
18+
}
19+
]
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<html><head>
2+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
3+
</head>
4+
<body>
5+
<div style="background-color:#FFEB9C; width:100%; padding:2pt; font-size:10pt; line-height:12pt; font-family:'Calibri'; color:Black; text-align: left;">
6+
<span style="color:#9C6500; font-weight:bold;">CAUTION:</span> This email has been sent from an external source. Do not click links, open attachments, or provide sensitive business information unless you can verify the sender’s legitimacy.
7+
</div>
8+
<br>
9+
<div>
10+
<p></p>
11+
<p></p>
12+
<p></p>
13+
<p><span style="color: black; font-family: tahoma, arial, helvetica, sans-serif; font-size: 10pt;">Dear Customer,</span></p>
14+
<p><span style="color: black; font-family: tahoma, arial, helvetica, sans-serif; font-size: 10pt;">Please note that this activity has been cancelled.
15+
</span></p>
16+
<p><span style="color: black; font-family: tahoma, arial, helvetica, sans-serif; font-size: 10pt;">The details for the same have been mentioned below:</span><strong><span style="color: black;">&nbsp;
17+
</span></strong></p>
18+
<table style="height: 42px; border-color: #000000;" border="0" width="623" cellspacing="0">
19+
<tbody>
20+
<tr style="background-color: #4b85c5;">
21+
<td style="border: none; text-align: left; padding-left: 5px;"><span style="font-size: 11pt; color: #ffffff; font-family: helvetica;"><strong>TATA COMMUNICATIONS</strong></span></td>
22+
<td style="border: 0.5px #bbbbbb;">&nbsp;<img style="align: baseline;" title="" src="cid:[email protected]" alt="" width="44" height="38" align="right" border="" hspace="10" vspace=""></td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
<table style="height: 38px; border-color: #000000;" border="1" width="620" cellspacing="0">
27+
<tbody>
28+
<tr>
29+
<td style="background-color: #4b85c5;" colspan="2"><span style="color: #ffffff; font-family: arial, helvetica, sans-serif; font-size: 12pt;">&nbsp;Planned Work Notification</span></td>
30+
</tr>
31+
<tr>
32+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">Ticket Reference - TCL</span></strong></span></td>
33+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">CHGP0123456</span></td>
34+
</tr>
35+
<tr>
36+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">Service ID</span></strong></span></td>
37+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">01234567890123456789</span></td>
38+
</tr>
39+
<tr>
40+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">NIMS ID</span></strong></span></td>
41+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"></span></td>
42+
</tr>
43+
<tr>
44+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Maintenance Type</span></strong></strong></span></td>
45+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Normal</span></td>
46+
</tr>
47+
<tr>
48+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Activity Status</span></strong></strong></span></td>
49+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Canceled</span></td>
50+
</tr>
51+
<tr>
52+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Execution Owner</span></strong></strong></span></td>
53+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">3rd party service Provider</span></td>
54+
</tr>
55+
<tr>
56+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Location of activity</span></strong></strong></span></td>
57+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">LONDON</span></td>
58+
</tr>
59+
<tr>
60+
<td style="background-color: #4b85c5;" colspan="2">&nbsp;</td>
61+
</tr>
62+
<tr>
63+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Activity Window (IST)</span></strong></strong></span></td>
64+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">2024-11-21 04:30:00 IST to 2024-11-22 10:30:00 IST</span></td>
65+
</tr>
66+
<tr>
67+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Activity Window (GMT)</span></strong></strong></span></td>
68+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">2024-11-20 23:00:00 GMT to 2024-11-22 05:00:00 GMT</span></td>
69+
</tr>
70+
<tr>
71+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><strong><span style="color: black;">Expected Impact Duration(DD:HH:MM) :</span></strong></strong></span></td>
72+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">6 Hours</span></td>
73+
</tr>
74+
<tr>
75+
<td style="background-color: #4b85c5;" colspan="2">&nbsp;</td>
76+
</tr>
77+
<tr>
78+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><strong><span style="color: black;">Activity Description</span></strong></span></td>
79+
<td><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">&nbsp;Third party service provider will execute network maintenance activity for Network redevelopment.<br>
80+
Services will be impacted for 6 hrs on each Days.</span></td>
81+
</tr>
82+
<tr>
83+
<td colspan="2">
84+
<p><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">We request you to reschedule sensitive operations at your end accordingly.<br>
85+
We apologize for any inconvenience due to this event and resulting downtime.<br>
86+
If you have any queries with respect to this activity, feel free to contact us on the coordinates mentioned below:<br>
87+
Mail ID :<a href="mailto:[email protected]">[email protected]</a><br>
88+
Contact Number : + 91 20 6614 4444 &amp; Toll Free no: 1-8002660660<br>
89+
We look forward to your co-operation and a long term synergic association.<br>
90+
Best Regards,<br>
91+
Customer Service<br>
92+
TATA COMMUNICATIONS</span></p>
93+
</td>
94+
</tr>
95+
</tbody>
96+
</table>
97+
<p>&nbsp;</p>
98+
<div>&nbsp;</div>
99+
<div style="display:inline">Ref:MSGTCL000143017654</div>
100+
</div>
101+
</body>
102+
</html>
103+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"account": "N/A",
4+
"circuits": [
5+
{
6+
"circuit_id": "01234567890123456789",
7+
"impact": "OUTAGE"
8+
}
9+
],
10+
"end": 1732251600,
11+
"maintenance_id": "CHGP0123456",
12+
"organizer": "[email protected]",
13+
"start": 1732143600
14+
}
15+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cancellation Notification /TCL TT: "CHGP0123456" / "Normal" / "Canceled" / Planned Work Notification
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"status": "CANCELLED",
4+
"summary": "Cancellation Notification /TCL TT: \"CHGP0123456\" / \"Normal\" / \"Canceled\" / Planned Work Notification"
5+
}
6+
]

0 commit comments

Comments
 (0)