-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into issue-56-stamp-parser
- Loading branch information
Showing
22 changed files
with
684 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
"""Seaborn parser.""" | ||
import logging | ||
import re | ||
|
||
from dateutil import parser | ||
|
||
from circuit_maintenance_parser.errors import ParserError | ||
from circuit_maintenance_parser.parser import CircuitImpact, Html, Impact, Status, EmailSubjectParser | ||
|
||
# pylint: disable=too-many-branches | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SubjectParserSeaborn1(EmailSubjectParser): | ||
"""Parser for Seaborn subject string, email type 1. | ||
Subject: [{ACOUNT NAME}] {MAINTENACE ID} {DATE} | ||
[Customer Direct] 1111 08/14 | ||
""" | ||
|
||
def parse_subject(self, subject): | ||
"""Parse subject of email file.""" | ||
data = {} | ||
try: | ||
search = re.search(r".+\[(.+)\].([0-9]+).+", subject) | ||
if search: | ||
data["account"] = search.group(1) | ||
data["maintenance_id"] = search.group(2) | ||
return [data] | ||
|
||
except Exception as exc: | ||
raise ParserError from exc | ||
|
||
|
||
class SubjectParserSeaborn2(EmailSubjectParser): | ||
"""Parser for Seaborn subject string, email type 2. | ||
Subject: [## {ACCOUNT NUMBER} ##] Emergency Maintenance Notification CID: {CIRCUIT} TT#{MAINTENACE ID} | ||
[## 11111 ##] Emergency Maintenance Notification CID: AAA-AAAAA-AAAAA-AAA1-1111-11 TT#1111 | ||
""" | ||
|
||
def parse_subject(self, subject): | ||
"""Parse subject of email file.""" | ||
data = {} | ||
try: | ||
search = re.search(r".+\[## ([0-9]+) ##\].+", subject) | ||
if search: | ||
data["account"] = search.group(1) | ||
return [data] | ||
|
||
except Exception as exc: | ||
raise ParserError from exc | ||
|
||
|
||
class HtmlParserSeaborn1(Html): | ||
"""Notifications HTML Parser 1 for Seaborn notifications. | ||
<div> | ||
<p>DESCRIPTION: This is a maintenance notification.</p> | ||
<p>SERVICE IMPACT: 05 MINUTE OUTAGE</p> | ||
<p>LOCATION: London</p> | ||
... | ||
</div> | ||
""" | ||
|
||
def parse_html(self, soup, data_base): | ||
"""Execute parsing.""" | ||
data = data_base.copy() | ||
try: | ||
self.parse_body(soup, data) | ||
return [data] | ||
|
||
except Exception as exc: | ||
raise ParserError from exc | ||
|
||
def parse_body(self, body, data): | ||
"""Parse HTML body.""" | ||
data["circuits"] = [] | ||
p_elements = body.find_all("p") | ||
|
||
for index, element in enumerate(p_elements): | ||
if "DESCRIPTION" in element.text: | ||
data["summary"] = element.text.split(":")[1].strip() | ||
elif "SCHEDULE" in element.text: | ||
schedule = p_elements[index + 1].text | ||
start, end = schedule.split(" - ") | ||
data["start"] = self.dt2ts(parser.parse(start)) | ||
data["end"] = self.dt2ts(parser.parse(end)) | ||
data["status"] = Status("CONFIRMED") | ||
elif "AFFECTED CIRCUIT" in element.text: | ||
circuit_id = element.text.split(": ")[1] | ||
data["circuits"].append(CircuitImpact(impact=Impact("OUTAGE"), circuit_id=circuit_id)) | ||
|
||
|
||
class HtmlParserSeaborn2(Html): | ||
"""Notifications HTML Parser 2 for Seaborn notifications. | ||
<div> | ||
<div>DESCRIPTION: This is a maintenance notification.</div> | ||
<div>SERVICE IMPACT: 05 MINUTE OUTAGE</div> | ||
<div>LOCATION: London</div> | ||
... | ||
</div> | ||
""" | ||
|
||
def parse_html(self, soup, data_base): | ||
"""Execute parsing.""" | ||
data = data_base.copy() | ||
try: | ||
self.parse_body(soup, data) | ||
return [data] | ||
|
||
except Exception as exc: | ||
raise ParserError from exc | ||
|
||
def parse_body(self, body, data): | ||
"""Parse HTML body.""" | ||
data["circuits"] = [] | ||
div_elements = body.find_all("div") | ||
for element in div_elements: | ||
if "Be advised" in element.text: | ||
if "been rescheduled" in element.text: | ||
data["status"] = Status["RE_SCHEDULED"] | ||
elif "been scheduled" in element.text: | ||
data["status"] = Status["CONFIRMED"] | ||
elif "Description" in element.text: | ||
data["summary"] = element.text.split(":")[1].strip() | ||
elif "Seaborn Ticket" in element.text: | ||
data["maintenance_id"] = element.text.split(":")[1] | ||
elif "Start date" in element.text: | ||
start = element.text.split(": ")[1] | ||
data["start"] = self.dt2ts(parser.parse(start)) | ||
elif "Finish date" in element.text: | ||
end = element.text.split(": ")[1] | ||
data["end"] = self.dt2ts(parser.parse(end)) | ||
elif "Circuit impacted" in element.text: | ||
circuit_id = self.remove_hex_characters(element.text).split(":")[1] | ||
data["circuits"].append(CircuitImpact(impact=Impact("OUTAGE"), circuit_id=circuit_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,12 @@ | |
from circuit_maintenance_parser.parsers.gtt import HtmlParserGTT1 | ||
from circuit_maintenance_parser.parsers.lumen import HtmlParserLumen1 | ||
from circuit_maintenance_parser.parsers.megaport import HtmlParserMegaport1 | ||
from circuit_maintenance_parser.parsers.seaborn import ( | ||
HtmlParserSeaborn1, | ||
HtmlParserSeaborn2, | ||
SubjectParserSeaborn1, | ||
SubjectParserSeaborn2, | ||
) | ||
from circuit_maintenance_parser.parsers.telstra import HtmlParserTelstra1 | ||
from circuit_maintenance_parser.parsers.turkcell import HtmlParserTurkcell1 | ||
from circuit_maintenance_parser.parsers.verizon import HtmlParserVerizon1 | ||
|
@@ -150,6 +156,16 @@ class PacketFabric(GenericProvider): | |
_default_organizer = "[email protected]" | ||
|
||
|
||
class Seaborn(GenericProvider): | ||
"""Seaborn provider custom class.""" | ||
|
||
_processors: List[GenericProcessor] = [ | ||
CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserSeaborn1, SubjectParserSeaborn1]), | ||
CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserSeaborn2, SubjectParserSeaborn2]), | ||
] | ||
_default_organizer = "[email protected]" | ||
|
||
|
||
class Telia(GenericProvider): | ||
"""Telia provider custom class.""" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Date: Mon, 16 Aug 2021 17:29:56 +0100 | ||
Message-ID: <CACtiu=[email protected]> | ||
Subject: Fwd: [rd-notices] Re:[## 99999 ##] Emergency Maintenance Notification | ||
CID: AAA-AAAAA-AAAAA-AAA1-00000-00 TT#7777 | ||
Content-Type: multipart/related; boundary="000000000000dfb73e05c9afb661" | ||
|
||
--000000000000dfb73e05c9afb661 | ||
Content-Type: multipart/alternative; boundary="000000000000dfb73c05c9afb660" | ||
--000000000000dfb73c05c9afb660 | ||
Content-Type: text/plain; charset="UTF-8" | ||
---------- Forwarded message --------- | ||
From: NOC Seaborn <[email protected]> | ||
Date: Wed, 11 Aug 2021 at 23:09 | ||
Subject: [rd-notices] Re:[## 99999 ##] Emergency Maintenance Notification | ||
CID: AAA-AAAAA-AAAAA-AAA1-00000-00 TT#7777 | ||
To: <[email protected]> | ||
|
||
--000000000000dfb73c05c9afb660 | ||
Content-Type: text/html; charset="UTF-8" | ||
Content-Transfer-Encoding: quoted-printable | ||
|
||
<div dir=3D"ltr"><br clear=3D"all"><div><div dir=3D"ltr" class=3D"gmail_sig= | ||
nature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div dir=3D"ltr= | ||
"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div = | ||
dir=3D"ltr"><p><span style=3D"background-color:rgb(255,255,255)" lang=3D"EN= | ||
-US"><font size=3D"2" face=3D"tahoma, sans-serif" color=3D"#000000">Be brig= | ||
ht</font></span></p> | ||
|
||
<table style=3D"border:none;border-collapse:collapse"><colgroup><col width= | ||
=3D"65"><col width=3D"241"></colgroup><tbody><tr style=3D"height:46pt"><td = | ||
style=3D"vertical-align:top;padding:5pt 5pt 5pt 5pt;overflow:hidden"><p dir= | ||
=3D"ltr" style=3D"line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span s= | ||
tyle=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:= | ||
transparent;vertical-align:baseline;white-space:pre-wrap"><span style=3D"bo= | ||
rder:none;display:inline-block;overflow:hidden;width:47px;height:48px"><img= | ||
src=3D"https://lh5.googleusercontent.com/U9uUZC2e3L55zxG_yWsPLz4ffrHQwFRbD= | ||
LJynW4VqWiW8f4SMROxnkrO0KZBZoV8Y3MZPEqbBHwShT5SyQ0VnQ7FuAEZfYvWTM6Ha5WVmXSq= | ||
qN8WOUFW1J726dGUynkZm7f4LsfH" width=3D"47" height=3D"48.01172447484123" sty= | ||
le=3D"margin-left:0px"></span></span></p></td><td style=3D"vertical-align:t= | ||
op;padding:5pt 5pt 5pt 5pt;overflow:hidden"><p dir=3D"ltr" style=3D"line-he= | ||
ight:1.2;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:9pt;fon= | ||
t-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:70= | ||
0;vertical-align:baseline;white-space:pre-wrap">Engineer</span></p><p = | ||
dir=3D"ltr" style=3D"line-height:1.2;margin-top:0pt;margin-bottom:0pt"><spa= | ||
n style=3D"font-size:9pt;font-family:Arial;color:rgb(0,0,0);background-colo= | ||
r:transparent;vertical-align:baseline;white-space:pre-wrap">Network Enginee= | ||
r III=C2=A0 |=C2=A0 Customer</span></p><p dir=3D"ltr" style=3D"line-heigh= | ||
t:1.2;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:9pt;font-f= | ||
amily:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:ba= | ||
seline;white-space:pre-wrap">Summoner: Customer Eng</span></p></td></tr></t= | ||
body></table></div></div></div></div></div></div></div></div></div><br><br>= | ||
<div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">----------= | ||
Forwarded message ---------<br>From: <strong class=3D"gmail_sendername" di= | ||
r=3D"auto">NOC Seaborn</strong> <span dir=3D"auto"><<a href=3D"mailto:no= | ||
[email protected]">[email protected]</a>></span><br>Date: Wed,= | ||
11 Aug 2021 at 23:09<br>Subject: [rd-notices] Re:[## 51346 ##] Emergency = | ||
Maintenance Notification CID: AAA-AAAAA-AAAA-AAA1-00000-00 TT#7777<br>To: = | ||
<<a href=3D"mailto:[email protected]">[email protected]</a= | ||
>><br></div><br><br><u></u><div><div style=3D"font-size:13px;font-family= | ||
:Arial,Helvetica,Verdana,sans-serif"><div><div>Dear Customer,<br></div><div><br= | ||
></div><div>=C2=A0</div><div><br></div><div>Be advised that this maintenanc= | ||
e has been rescheduled and the details are below:</div><div><br></div><div>= | ||
=C2=A0</div><div><br></div><div>Notification Details: Emergency=C2=A0 maint= | ||
enance.</div><div><br></div><div>Description: An emergency work will be car= | ||
ried out to relocate fiber cable due to civil works in the zone.</div><div>= | ||
<br></div><div>Seaborn Ticket number:7777<br></div><div>Start date/time: 8/= | ||
12/2021 2:00:00 am GMT</div><div><br></div><div>Finish date/time: 8/12/2021= | ||
11:00:00 am GMT</div><div><br></div><div>Circuit impacted:=AAA-AAAAA-AAAAA= | ||
-AAA1-00000-00<br><br></div><div>Service Impact: Switch hits UP to 5 mi= | ||
nutes</div><div>=C2=A0</div><div><br></div><div>We regret any inconvenience= | ||
this may cause you.</div><div><br></div><div>=C2=A0</div><div><br></div><d= | ||
iv>Regards,=C2=A0</div></div><div><br></div><div title=3D"sign_holder::star= | ||
t"></div><div><div style=3D"font-size:13px;font-family:Arial,Helvetica,Verd= | ||
ana,sans-serif"><div><div><img style=3D"padding:0px;max-width:100%;box-sizi= | ||
ng:border-box" src=3D"cid:17b4fcc3b448217e76e1"><br></div><div><br></div><d= | ||
iv>Engineer Name<br></div><div>NOC Engineer<br></= | ||
div><div>Seaborn Networks<br></div><div>1-201-351-5806 (US)<br></div><div>0= | ||
800-SEABRAS (0800 732-2727)(Brazil)<br></div><div><a rel=3D"noreferrer" hre= | ||
f=3D"mailto:[email protected]" target=3D"_blank">noc@seabornnetworks.= | ||
com</a><br></div><div><a rel=3D"noreferrer" href=3D"http://www.seabornneetw= | ||
orks.com/" target=3D"_blank">www.seabornnetworks.com</a><br></div><div><br = | ||
style=3D"font-family:Arial,Helvetica,Verdana,sans-serif"></div></div></div>= | ||
</div><div title=3D"sign_holder::end"></div><div><br></div><div title=3D"be= | ||
forequote:::"></div><div><blockquote style=3D"border-left:1px dotted rgb(22= | ||
9,229,229);margin-left:5px;padding-left:5px"><div style=3D"padding-top:10px= | ||
"> <br></div></blockquote></div> <div><br></div></div><div id=3D"m_-8814736= | ||
200534887510ZDeskInteg"></div><br></div> |
Oops, something went wrong.