From d34f2561304010bf748861e12339bc37d21b8503 Mon Sep 17 00:00:00 2001 From: carbonarok Date: Tue, 7 Sep 2021 11:58:23 +0100 Subject: [PATCH 1/7] Added HGC parser. --- circuit_maintenance_parser/__init__.py | 2 + circuit_maintenance_parser/parsers/hgc.py | 127 ++++++++++++ circuit_maintenance_parser/provider.py | 11 ++ tests/unit/data/hgc/hgc1.eml | 223 ++++++++++++++++++++++ tests/unit/data/hgc/hgc1_html_result.json | 15 ++ tests/unit/data/hgc/hgc1_result.json | 21 ++ tests/unit/data/hgc/hgc2.eml | 145 ++++++++++++++ tests/unit/data/hgc/hgc2_html_result.json | 15 ++ tests/unit/data/hgc/hgc2_result.json | 21 ++ tests/unit/test_e2e.py | 10 + tests/unit/test_parsers.py | 12 ++ 11 files changed, 602 insertions(+) create mode 100644 circuit_maintenance_parser/parsers/hgc.py create mode 100644 tests/unit/data/hgc/hgc1.eml create mode 100644 tests/unit/data/hgc/hgc1_html_result.json create mode 100644 tests/unit/data/hgc/hgc1_result.json create mode 100644 tests/unit/data/hgc/hgc2.eml create mode 100644 tests/unit/data/hgc/hgc2_html_result.json create mode 100644 tests/unit/data/hgc/hgc2_result.json diff --git a/circuit_maintenance_parser/__init__.py b/circuit_maintenance_parser/__init__.py index d20e9216..d7301076 100644 --- a/circuit_maintenance_parser/__init__.py +++ b/circuit_maintenance_parser/__init__.py @@ -9,6 +9,7 @@ Cogent, EUNetworks, GTT, + HGC, Lumen, Megaport, NTT, @@ -26,6 +27,7 @@ Cogent, EUNetworks, GTT, + HGC, Lumen, Megaport, NTT, diff --git a/circuit_maintenance_parser/parsers/hgc.py b/circuit_maintenance_parser/parsers/hgc.py new file mode 100644 index 00000000..4a84fd63 --- /dev/null +++ b/circuit_maintenance_parser/parsers/hgc.py @@ -0,0 +1,127 @@ +"""HGC parser.""" +import logging +import re + +from dateutil import parser + +from circuit_maintenance_parser.errors import ParserError +from circuit_maintenance_parser.parser import EmailSubjectParser, Html, Impact, CircuitImpact, Status + +# pylint: disable=too-many-branches + + +logger = logging.getLogger(__name__) + + +class SubjectParserHGC1(EmailSubjectParser): + """HGC subject parser.""" + + def parse_subject(self, subject): + """Parse HGC subject string.""" + data = {} + try: + search = re.search(r"^.+\((.+)\)", subject.replace("\n", "")) + if search: + data["maintenance_id"] = search.group(1) + else: + split = subject.split(" | ") + data["maintenance_id"] = split[2] + return [data] + except Exception as exc: + raise ParserError from exc + + +class HtmlParserHGC1(Html): + """HGC HTML parser.""" + + def parse_html(self, soup, data_base): + """Execute parsing.""" + data = data_base.copy() + try: + self.parse_table(soup.find_all("table"), data) + data["status"] = Status.CONFIRMED + return [data] + + except Exception as exc: + raise ParserError from exc + + def parse_table(self, tables, data): + """Parse HTML tables. + + + + + + + + + + + + + ... +

Circuit ID

:

CIR00000001

Customer

:

Network to Code

+ """ + circuit_id = None + for table in tables: + td_elements = table.find_all("td") + for idx, td_element in enumerate(td_elements): + if "circuit id" in td_element.text.lower(): + circuit_id = td_elements[idx + 2].text.strip() + elif "customer" in td_element.text.lower(): + data["account"] = td_elements[idx + 2].text.strip() + elif "maintenance window start date" in td_element.text.lower(): + data["start"] = self.dt2ts(parser.parse(td_elements[idx + 2].text.strip())) + elif "maintenance window end date" in td_element.text.lower(): + data["end"] = self.dt2ts(parser.parse(td_elements[idx + 2].text.strip())) + elif "description" in td_element.text.lower(): + data["summary"] = td_elements[idx + 2].text.strip() + elif "service impact" in td_element.text.lower(): + if "down throughout maintenance window" in td_elements[idx + 2].text: + impact = Impact("OUTAGE") + else: + impact = Impact("OUTAGE") + data["circuits"] = [CircuitImpact(impact=impact, circuit_id=circuit_id)] + + +class HtmlParserHGC2(Html): + """HGC HTML parser.""" + + def parse_html(self, soup, data_base): + """Execute parsing.""" + data = data_base.copy() + try: + self.parse_body(soup.find_all("span"), data) + data["status"] = Status.CONFIRMED + return [data] + + except Exception as exc: + raise ParserError from exc + + def parse_body(self, span_elements, data): + """Parse HTML body. + +
+ Circuit ID:CIR000001 + Customer:Network to Code + ... +
+ """ + circuit_id = None + for span_element in span_elements: + if "circuit id:" in span_element.text.lower(): + circuit_id = span_element.text.split(":")[1].strip() + elif "customer:" in span_element.text.lower(): + data["account"] = span_element.text.split(":")[1].strip() + elif "maintenance window start date" in span_element.text.lower(): + data["start"] = self.dt2ts(parser.parse(span_element.text.split(":")[1].strip())) + elif "maintenance window end date" in span_element.text.lower(): + data["end"] = self.dt2ts(parser.parse(span_element.text.split(":")[1].strip())) + elif "description:" in span_element.text.lower(): + data["summary"] = span_element.text.split(":")[1].strip() + elif "service impact:" in span_element.text.lower(): + if "down throughout maintenance window" in span_element.text.split(":")[1]: + impact = Impact("OUTAGE") + else: + impact = Impact("OUTAGE") + data["circuits"] = [CircuitImpact(impact=impact, circuit_id=circuit_id)] diff --git a/circuit_maintenance_parser/provider.py b/circuit_maintenance_parser/provider.py index 6eace75e..8e552dc5 100644 --- a/circuit_maintenance_parser/provider.py +++ b/circuit_maintenance_parser/provider.py @@ -16,6 +16,7 @@ from circuit_maintenance_parser.parsers.cogent import HtmlParserCogent1 from circuit_maintenance_parser.parsers.gtt import HtmlParserGTT1 +from circuit_maintenance_parser.parsers.hgc import HtmlParserHGC1, HtmlParserHGC2, SubjectParserHGC1 from circuit_maintenance_parser.parsers.lumen import HtmlParserLumen1 from circuit_maintenance_parser.parsers.megaport import HtmlParserMegaport1 from circuit_maintenance_parser.parsers.seaborn import ( @@ -126,6 +127,16 @@ class GTT(GenericProvider): _default_organizer = "InfraCo.CM@gttcorp.org" +class HGC(GenericProvider): + """HGC provider custom class.""" + + _processors: List[GenericProcessor] = [ + CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserHGC1, SubjectParserHGC1]), + CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserHGC2, SubjectParserHGC1]), + ] + _default_organizer = "HGCINOCPW@hgc.com.hk" + + class Lumen(GenericProvider): """Lumen provider custom class.""" diff --git a/tests/unit/data/hgc/hgc1.eml b/tests/unit/data/hgc/hgc1.eml new file mode 100644 index 00000000..55890efa --- /dev/null +++ b/tests/unit/data/hgc/hgc1.eml @@ -0,0 +1,223 @@ +X-Received: by 2002:a2e:b80f:: with SMTP id u15mr10092348ljo.232.1629131494669; + Mon, 16 Aug 2021 09:31:34 -0700 (PDT) +MIME-Version: 1.0 +Date: Mon, 16 Aug 2021 17:31:23 +0100 +Message-ID: +Subject: Fwd: [rd-notices] [Emergency] HGC Maintenance Work Notification - + Customer Inc | CIR000001 | TIC000000000000001 +Content-Type: multipart/related; boundary="00000000000008848c05c9afbc4c" + +--00000000000008848c05c9afbc4c +Content-Type: multipart/alternative; boundary="00000000000008848c05c9afbc4b" + +--00000000000008848c05c9afbc4b +Content-Type: text/html; charset="UTF-8" +Content-Transfer-Encoding: quoted-printable + +
+
+

Dear Customer, +

+


+
Please be= + advised that there will be emergency maintenance work by International ser= +vice provider. Below are the details: +
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Circuit ID

+
+

:

+
+

CIR000001

+
+

Customer

+
+

:

+
+

Account Name

+
+

Maintenance Window start date & time

+
+

:

+
+

15-Aug-2021=C2=A0 07:01 UTC

+
+

Maintenance Window end date & time

+
+

:

+
+

15-Aug-2021=C2=A0 12:00 UTC

+
+

Service Impact

+
+

:

+
+

Down throughout maintenance window

+
+

Description

+
+

:

+
+

Service provider performing fault isolation and hardware replacement= + in London.

+
+

=C2=A0 +
+
Regret th= +at the maintenance notification are sent to you with short notice because o= +ur service provider just found maintenance needed to be performed ASAP, oth= +erwise the service + will be interrupted under uncontrolled situation.
+
We thank = +you for your attention and apologize for any inconvenience for the planned = +maintenance work +
+
=C2=A0 +
+
=C2=A0

+

Best Reg= +ards
+Hafizul
+Planned Maintenance Work
+International Business Engineering & Operations
+
HGC Global Communications Ltd<= +u>

+

Tel:=C2= +=A0=C2=A0=C2=A0 +852-39050037/+852 39050038

+

=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 +852-31561500(option= +al)

+

Email:=C2= +=A0<= +span style=3D"font-size:9.0pt;font-family:"Arial",sans-serif">hgc= +inocpw@hgc.com.hk

+

= +3D"HGC

+

=C2=A0

+


+
+

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+
+Disclaimer: This email, the information and any attachments contained herei= +n are intended solely for the addressee or addressees. It may be confidenti= +al and legally privileged. If you are not an intended recipient, please del= +ete the message and any attachments + and notify the sender. Any use or disclosure of the contents is unauthoriz= +ed and may be unlawful. To know more, please click +here. Email transmission cannot be guaranteed to be secure or e= +rror-free. We therefore do not accept liability for any loss or damage hows= +oever arising as a result of email transmission +
+ +--00000000000008848c05c9afbc4b-- diff --git a/tests/unit/data/hgc/hgc1_html_result.json b/tests/unit/data/hgc/hgc1_html_result.json new file mode 100644 index 00000000..9813770f --- /dev/null +++ b/tests/unit/data/hgc/hgc1_html_result.json @@ -0,0 +1,15 @@ +[ + { + "account": "Account Name", + "circuits": [ + { + "circuit_id": "CIR000001", + "impact": "OUTAGE" + } + ], + "end": 1629028800, + "start": 1629010860, + "status": "CONFIRMED", + "summary": "Service provider performing fault isolation and hardware replacement in London." + } +] \ No newline at end of file diff --git a/tests/unit/data/hgc/hgc1_result.json b/tests/unit/data/hgc/hgc1_result.json new file mode 100644 index 00000000..546347f5 --- /dev/null +++ b/tests/unit/data/hgc/hgc1_result.json @@ -0,0 +1,21 @@ +[ + { + "account": ":", + "circuits": [ + { + "circuit_id": "CIR000001", + "impact": "OUTAGE" + } + ], + "end": 1629028800, + "maintenance_id": "TIC000000000000001", + "organizer": "HGCINOCPW@hgc.com.hk", + "provider": "hgc", + "sequence": 1, + "stamp": 1629131483, + "start": 1629010860, + "status": "CONFIRMED", + "summary": "Service provider performing fault isolation and hardware replacement in London.", + "uid": "0" + } +] \ No newline at end of file diff --git a/tests/unit/data/hgc/hgc2.eml b/tests/unit/data/hgc/hgc2.eml new file mode 100644 index 00000000..8224b510 --- /dev/null +++ b/tests/unit/data/hgc/hgc2.eml @@ -0,0 +1,145 @@ +MIME-Version: 1.0 +Date: Mon, 16 Aug 2021 17:31:56 +0100 +Message-ID: +Subject: Fwd: [rd-notices] HGC Maintenance Work Notification - Customer Inc + _ CIR0000001 (TIC000000000000001) +Content-Type: multipart/related; boundary="000000000000052c3d05c9afbee0" + +--000000000000052c3d05c9afbee0 +Content-Type: multipart/alternative; boundary="000000000000052c3c05c9afbedf" + +--000000000000052c3c05c9afbedf +Content-Type: text/html; charset="UTF-8" +Content-Transfer-Encoding: quoted-printable + +
+
+

Dear Customer, +

+


+
Please be= + advised that there will be maintenance work by International service provi= +der. Below are the details: +
+
=C2=A0 +
+
Circuit I= +D:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CIR0000001=C2=A0=C2=A0=C2=A0 +
+
Customer:= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0 Customer Inc

+

Maintenance Window start date & time:=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0 08-Jul-2021 17:00 UTC +
+
Maintenan= +ce Window end date & time:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 08= +-Jul-2021 18:00 UTC +
+
Service I= +mpact:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 1 hour downtime
+
Descripti= +on:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= +=A0=C2=A0=C2=A0 Cable fiber relocation +between Tokyo an= +d Wada by International service provider
+
=C2=A0 +
+
The conte= +nt of this activity notice has been agreed and understood in case HGC do no= +t receive any response within 24 hours from the time advisory was sent +
+
We thank = +you for your attention and apologize for any inconvenience for the planned = +maintenance work +
+
=C2=A0 +
+
=C2=A0

+

Best Reg= +ards
+Amran
+Planned Maintenance Work
+International Business Engineering & Operations
+
HGC Global Communications Ltd<= +u>

+

Tel:=C2= +=A0=C2=A0=C2=A0 +852-39050037/+852 39050038

+

=C2=A0= +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 +852-31561500(option= +al)

+

Email:=C2= +=A0<= +span style=3D"font-size:9.0pt;font-family:"Arial",sans-serif">hgc= +inocpw@hgc.com.hk

+

3D"HGC= +

+

=C2=A0

+


+
+

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+

=C2=A0

+
+

Disclaimer: This email, the information and any attachments contained he= +rein are intended solely for the addressee or addressees. It may be confide= +ntial and legally privileged. If you are not an intended recipient, please = +delete the message and any attachments + and notify the sender. Any use or disclosure of the contents is unauthoriz= +ed and may be unlawful. To know more, please click here. +
+
+Email transmission cannot be guaranteed to be secure or error-free. We ther= +efore do not accept liability for any loss or damage howsoever arising as a= + result of email transmission.

+
+ +--000000000000052c3c05c9afbedf-- diff --git a/tests/unit/data/hgc/hgc2_html_result.json b/tests/unit/data/hgc/hgc2_html_result.json new file mode 100644 index 00000000..03107b74 --- /dev/null +++ b/tests/unit/data/hgc/hgc2_html_result.json @@ -0,0 +1,15 @@ +[ + { + "account": "Customer Inc", + "circuits": [ + { + "circuit_id": "CIR0000001", + "impact": "OUTAGE" + } + ], + "end": 1625767200, + "start": 1625763600, + "status": "CONFIRMED", + "summary": "Cable fiber relocation" + } +] \ No newline at end of file diff --git a/tests/unit/data/hgc/hgc2_result.json b/tests/unit/data/hgc/hgc2_result.json new file mode 100644 index 00000000..35e7e4cb --- /dev/null +++ b/tests/unit/data/hgc/hgc2_result.json @@ -0,0 +1,21 @@ +[ + { + "account": "Account Name", + "circuits": [ + { + "circuit_id": "CIR000001", + "impact": "OUTAGE" + } + ], + "end": 1629028800, + "maintenance_id": "TIC000000000000001", + "organizer": "HGCINOCPW@hgc.com.hk", + "provider": "hgc", + "sequence": 1, + "stamp": 1629131483, + "start": 1629010860, + "status": "CONFIRMED", + "summary": "Service provider performing fault isolation and hardware replacement in London.", + "uid": "0" + } +] \ No newline at end of file diff --git a/tests/unit/test_e2e.py b/tests/unit/test_e2e.py index 5dd1ce60..eb40ff4b 100644 --- a/tests/unit/test_e2e.py +++ b/tests/unit/test_e2e.py @@ -14,6 +14,7 @@ GenericProvider, Cogent, EUNetworks, + HGC, Lumen, Megaport, NTT, @@ -62,6 +63,15 @@ ), # EUNetworks (EUNetworks, [("ical", GENERIC_ICAL_DATA_PATH),], [GENERIC_ICAL_RESULT_PATH,],), + # HGC + ( + HGC, + [ + ("email", Path(dir_path, "data", "hgc", "hgc1.eml")), + ("email", Path(dir_path, "data", "hgc", "hgc2.eml")), + ], + [Path(dir_path, "data", "hgc", "hgc1_result.json"), Path(dir_path, "data", "hgc", "hgc2_result.json"),], + ), # Lumen ( Lumen, diff --git a/tests/unit/test_parsers.py b/tests/unit/test_parsers.py index ece566e2..7ab5a66d 100644 --- a/tests/unit/test_parsers.py +++ b/tests/unit/test_parsers.py @@ -8,6 +8,7 @@ from circuit_maintenance_parser.parser import ICal, EmailDateParser from circuit_maintenance_parser.parsers.cogent import HtmlParserCogent1 from circuit_maintenance_parser.parsers.gtt import HtmlParserGTT1 +from circuit_maintenance_parser.parsers.hgc import HtmlParserHGC1, HtmlParserHGC2 from circuit_maintenance_parser.parsers.lumen import HtmlParserLumen1 from circuit_maintenance_parser.parsers.megaport import HtmlParserMegaport1 from circuit_maintenance_parser.parsers.seaborn import ( @@ -61,6 +62,17 @@ Path(dir_path, "data", "gtt", "gtt3.html"), Path(dir_path, "data", "gtt", "gtt3_result.json"), ), + # HGC + ( + HtmlParserHGC1, + Path(dir_path, "data", "hgc", "hgc1.eml"), + Path(dir_path, "data", "hgc", "hgc1_html_result.json"), + ), + ( + HtmlParserHGC2, + Path(dir_path, "data", "hgc", "hgc2.eml"), + Path(dir_path, "data", "hgc", "hgc2_html_result.json"), + ), # Lumen ( HtmlParserLumen1, From fb8a286ef58ae89a3e6ced9ee16c63fa3c210fcb Mon Sep 17 00:00:00 2001 From: carbonarok Date: Tue, 7 Sep 2021 12:02:21 +0100 Subject: [PATCH 2/7] Modified readmen and changelog. --- CHANGELOG.md | 1 + README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec96315..d948b2e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - #60 - Added new provider `Seaborn` using `Html` and a new parser for Email Subject: `EmailSubjectParser` - #66 - Added new provider `Momentum` using `Html` and `EmailSubjectParser` - #61 - Added new provider `Colt` using `ICal` and `Csv` +- #68 - Added new provider `HGC` using `Html` and `EmailSubjectParser` ### Fixed diff --git a/README.md b/README.md index e3cf1259..f8be2b3a 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ By default, there is a `GenericProvider` that support a `SimpleProcessor` using - Cogent - Colt - GTT +- HGC - Lumen - Megaport - Momentum From 11369d79db9399d310a6c05f5e60438a97ab13f7 Mon Sep 17 00:00:00 2001 From: carbonarok Date: Tue, 7 Sep 2021 17:49:24 +0100 Subject: [PATCH 3/7] Added docstring examples. --- circuit_maintenance_parser/parsers/hgc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/circuit_maintenance_parser/parsers/hgc.py b/circuit_maintenance_parser/parsers/hgc.py index 4a84fd63..945d4f7c 100644 --- a/circuit_maintenance_parser/parsers/hgc.py +++ b/circuit_maintenance_parser/parsers/hgc.py @@ -17,7 +17,12 @@ class SubjectParserHGC1(EmailSubjectParser): """HGC subject parser.""" def parse_subject(self, subject): - """Parse HGC subject string.""" + """Parse HGC subject string. + + Examples: + HGC Maintenance Work Notification - Network to Code _ CIR0000001 (TIC00000000000001) + HGC Maintenance Work Notification - Network to Code | CIR0000001 | TIC00000000000001 + """ data = {} try: search = re.search(r"^.+\((.+)\)", subject.replace("\n", "")) From 512c50be3c3702df21df7c0043c495f6898aebed Mon Sep 17 00:00:00 2001 From: carbonarok Date: Tue, 7 Sep 2021 17:57:31 +0100 Subject: [PATCH 4/7] Fixed pylint argument error. --- circuit_maintenance_parser/parsers/hgc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/circuit_maintenance_parser/parsers/hgc.py b/circuit_maintenance_parser/parsers/hgc.py index 945d4f7c..4b4fe558 100644 --- a/circuit_maintenance_parser/parsers/hgc.py +++ b/circuit_maintenance_parser/parsers/hgc.py @@ -39,9 +39,9 @@ def parse_subject(self, subject): class HtmlParserHGC1(Html): """HGC HTML parser.""" - def parse_html(self, soup, data_base): + def parse_html(self, soup): """Execute parsing.""" - data = data_base.copy() + data = {} try: self.parse_table(soup.find_all("table"), data) data["status"] = Status.CONFIRMED @@ -92,9 +92,9 @@ def parse_table(self, tables, data): class HtmlParserHGC2(Html): """HGC HTML parser.""" - def parse_html(self, soup, data_base): + def parse_html(self, soup): """Execute parsing.""" - data = data_base.copy() + data = {} try: self.parse_body(soup.find_all("span"), data) data["status"] = Status.CONFIRMED From 05038fddffa0f28a9065c13366c848501015448b Mon Sep 17 00:00:00 2001 From: carbonarok Date: Tue, 7 Sep 2021 18:04:21 +0100 Subject: [PATCH 5/7] Removed try and except login from parse_html --- circuit_maintenance_parser/parsers/hgc.py | 27 +++++++++-------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/circuit_maintenance_parser/parsers/hgc.py b/circuit_maintenance_parser/parsers/hgc.py index 4b4fe558..90a00e98 100644 --- a/circuit_maintenance_parser/parsers/hgc.py +++ b/circuit_maintenance_parser/parsers/hgc.py @@ -39,16 +39,13 @@ def parse_subject(self, subject): class HtmlParserHGC1(Html): """HGC HTML parser.""" - def parse_html(self, soup): + def parse_html(self, soup, data_base): """Execute parsing.""" - data = {} - try: - self.parse_table(soup.find_all("table"), data) - data["status"] = Status.CONFIRMED - return [data] + data = data_base.copy() + self.parse_table(soup.find_all("table"), data) + data["status"] = Status.CONFIRMED + return [data] - except Exception as exc: - raise ParserError from exc def parse_table(self, tables, data): """Parse HTML tables. @@ -92,16 +89,12 @@ def parse_table(self, tables, data): class HtmlParserHGC2(Html): """HGC HTML parser.""" - def parse_html(self, soup): + def parse_html(self, soup, data_base): """Execute parsing.""" - data = {} - try: - self.parse_body(soup.find_all("span"), data) - data["status"] = Status.CONFIRMED - return [data] - - except Exception as exc: - raise ParserError from exc + data = data_base.copy() + self.parse_body(soup.find_all("span"), data) + data["status"] = Status.CONFIRMED + return [data] def parse_body(self, span_elements, data): """Parse HTML body. From 143b3d1dba1fdf69a8723f5ce2035b76ce747ae4 Mon Sep 17 00:00:00 2001 From: carbonarok Date: Tue, 7 Sep 2021 18:06:35 +0100 Subject: [PATCH 6/7] Removed try and except. --- circuit_maintenance_parser/parsers/hgc.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/circuit_maintenance_parser/parsers/hgc.py b/circuit_maintenance_parser/parsers/hgc.py index 90a00e98..6395860c 100644 --- a/circuit_maintenance_parser/parsers/hgc.py +++ b/circuit_maintenance_parser/parsers/hgc.py @@ -24,16 +24,13 @@ def parse_subject(self, subject): HGC Maintenance Work Notification - Network to Code | CIR0000001 | TIC00000000000001 """ data = {} - try: - search = re.search(r"^.+\((.+)\)", subject.replace("\n", "")) - if search: - data["maintenance_id"] = search.group(1) - else: - split = subject.split(" | ") - data["maintenance_id"] = split[2] - return [data] - except Exception as exc: - raise ParserError from exc + search = re.search(r"^.+\((.+)\)", subject.replace("\n", "")) + if search: + data["maintenance_id"] = search.group(1) + else: + split = subject.split(" | ") + data["maintenance_id"] = split[2] + return [data] class HtmlParserHGC1(Html): From 4874a32e576f8f33918d760971553e66fc588f29 Mon Sep 17 00:00:00 2001 From: carbonarok Date: Tue, 7 Sep 2021 18:13:22 +0100 Subject: [PATCH 7/7] Fixes after merge. --- circuit_maintenance_parser/parsers/hgc.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/circuit_maintenance_parser/parsers/hgc.py b/circuit_maintenance_parser/parsers/hgc.py index 6395860c..db48e38a 100644 --- a/circuit_maintenance_parser/parsers/hgc.py +++ b/circuit_maintenance_parser/parsers/hgc.py @@ -4,7 +4,6 @@ from dateutil import parser -from circuit_maintenance_parser.errors import ParserError from circuit_maintenance_parser.parser import EmailSubjectParser, Html, Impact, CircuitImpact, Status # pylint: disable=too-many-branches @@ -34,16 +33,15 @@ def parse_subject(self, subject): class HtmlParserHGC1(Html): - """HGC HTML parser.""" + """HGC HTML 1 parser.""" - def parse_html(self, soup, data_base): + def parse_html(self, soup): """Execute parsing.""" - data = data_base.copy() + data = {} self.parse_table(soup.find_all("table"), data) data["status"] = Status.CONFIRMED return [data] - def parse_table(self, tables, data): """Parse HTML tables. @@ -84,11 +82,11 @@ def parse_table(self, tables, data): class HtmlParserHGC2(Html): - """HGC HTML parser.""" + """HGC HTML 2 parser.""" - def parse_html(self, soup, data_base): + def parse_html(self, soup): """Execute parsing.""" - data = data_base.copy() + data = {} self.parse_body(soup.find_all("span"), data) data["status"] = Status.CONFIRMED return [data]