-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AquaComms #75
Merged
Merged
AquaComms #75
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8582ddb
Added AquaComms provider.
carbonarok f397394
Removed unused imoprts.
carbonarok b6042c1
Fixed wrong data.
carbonarok 3c2a7d6
Change from strftime to timestamp.
carbonarok cc952fe
Black
carbonarok 58acec2
Removed timezone
carbonarok 4142cde
Fixed timezone testing.
carbonarok 9625280
Modifed regex. Added summary data.
carbonarok c7734ca
Update docs.
carbonarok 3125771
Fixed doc string
carbonarok 3c0a638
Merge branch 'develop' into kc_aquacomms
carbonarok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""Turkcell parser.""" | ||
import logging | ||
import re | ||
from datetime import datetime | ||
|
||
from circuit_maintenance_parser.parser import EmailSubjectParser, Html, Impact, CircuitImpact, Status | ||
|
||
# pylint: disable=too-many-nested-blocks, too-many-branches | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SubjectParserAquaComms1(EmailSubjectParser): | ||
"""Parser for Seaborn subject string, email type 1.""" | ||
|
||
def parse_subject(self, subject): | ||
"""Parse subject of email file. | ||
|
||
Subject: Aqua Comms Planned Outage Work ISSUE=111111 PROJ=999 | ||
""" | ||
data = {} | ||
search = re.search(r"ISSUE=([0-9]+).PROJ=([0-9]+)", subject) | ||
if search: | ||
data["maintenance_id"] = search.group(1) | ||
data["account"] = search.group(2) | ||
return [data] | ||
|
||
|
||
class HtmlParserAquaComms1(Html): | ||
"""Notifications Parser for AquaComms notifications.""" | ||
|
||
def parse_html(self, soup): | ||
"""Execute parsing.""" | ||
data = {} | ||
self.parse_tables(soup.find_all("table"), data) | ||
return [data] | ||
|
||
@staticmethod | ||
def get_tr_value(element): | ||
"""Remove new lines and split key to value.""" | ||
return element.text.replace("\n", "").split(": ")[1].strip() | ||
|
||
def parse_tables(self, tables, data): | ||
"""Parse HTML tables. | ||
|
||
<table> | ||
<tbody> | ||
<tr> | ||
<td><font>Ticket Number:</font></td> | ||
<td><font>11111</font></td> | ||
</tr> | ||
<tr> | ||
<td><font>Scheduled Start Date & Time:</font></td> | ||
<td><font>22:00 12/10/2020 GMT</font></td> | ||
</tr> | ||
<tr> | ||
<td><font>Scheduled End Date & Time:</font></td> | ||
<td><font>22:00 12/10/2020 GMT</font></td> | ||
</tr> | ||
... | ||
</tbody> | ||
</table> | ||
""" | ||
for table in tables: | ||
for tr_element in table.find_all("tr"): | ||
if "ticket number" in tr_element.text.lower(): | ||
data["maintenance_id"] = self.get_tr_value(tr_element) | ||
elif "update" in tr_element.text.lower(): | ||
data["summary"] = tr_element.text.replace("\n", "").split(" - ")[1] | ||
elif "scheduled start date" in tr_element.text.lower(): | ||
data["start"] = self.dt2ts(datetime.strptime(self.get_tr_value(tr_element), "%H:%M %d/%m/%Y %Z")) | ||
elif "scheduled end date" in tr_element.text.lower(): | ||
data["end"] = self.dt2ts(datetime.strptime(self.get_tr_value(tr_element), "%H:%M %d/%m/%Y %Z")) | ||
elif "service id" in tr_element.text.lower(): | ||
data["circuits"] = [ | ||
CircuitImpact(circuit_id=self.get_tr_value(tr_element), impact=Impact("OUTAGE")) | ||
] | ||
data["status"] = Status.CONFIRMED |
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from circuit_maintenance_parser.errors import ProcessorError, ProviderError | ||
from circuit_maintenance_parser.processor import CombinedProcessor, SimpleProcessor, GenericProcessor | ||
|
||
from circuit_maintenance_parser.parsers.aquacomms import HtmlParserAquaComms1, SubjectParserAquaComms1 | ||
from circuit_maintenance_parser.parsers.cogent import HtmlParserCogent1 | ||
from circuit_maintenance_parser.parsers.colt import ICalParserColt1, CsvParserColt1 | ||
from circuit_maintenance_parser.parsers.gtt import HtmlParserGTT1 | ||
|
@@ -105,6 +106,15 @@ def get_provider_type(cls) -> str: | |
#################### | ||
|
||
|
||
class AquaComms(GenericProvider): | ||
"""AquaComms provider custom class.""" | ||
|
||
_processors: List[GenericProcessor] = [ | ||
CombinedProcessor(data_parsers=[EmailDateParser, HtmlParserAquaComms1, SubjectParserAquaComms1]), | ||
] | ||
_default_organizer = "[email protected]" | ||
|
||
|
||
class Cogent(GenericProvider): | ||
"""Cogent 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,91 @@ | ||
MIME-Version: 1.0 | ||
Date: Thu, 26 Aug 2021 18:22:09 +0100 | ||
Subject: Aqua Comms Planned Outage Work ISSUE=11111 PROJ=999 | ||
Content-Type: multipart/alternative; boundary="000000000000015b7605ca799cf2" | ||
|
||
--000000000000015b7605ca799cf2 | ||
Content-Type: text/html; charset="UTF-8" | ||
Content-Transfer-Encoding: quoted-printable | ||
|
||
<font face=3D"Arial, Verdana, Helvetica, sans-serif" size=3D"2"> | ||
When replying, type your text above this line. | ||
<hr> | ||
<br> | ||
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0"> | ||
<tbody><tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2">Dear Network to Code,<br><br></font></td> | ||
</tr> | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2">This notice is being sent to notify you of t= | ||
he following Maintenance Event.<br><br></font></td> | ||
</tr> | ||
|
||
</tbody></table> | ||
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0"> | ||
<tbody><tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2"><b> Ticket Number: </b></font></td> | ||
<td valign=3D"TOP" align=3D"LEFT" style=3D"padding-left:10px"><font= | ||
face=3D"Arial, Verdana, Helvetica, sans-serif" size=3D"2"> 11111</font></t= | ||
d> | ||
</tr> | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2"><b> Scheduled Start Date & Time: </b></f= | ||
ont></td> | ||
<td valign=3D"TOP" align=3D"LEFT" style=3D"padding-left:10px"><font= | ||
face=3D"Arial, Verdana, Helvetica, sans-serif" size=3D"2"> 22:00 12/10/202= | ||
0 GMT</font></td> | ||
</tr> | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2"><b> Scheduled End Date & Time: </b></fon= | ||
t></td> | ||
<td valign=3D"TOP" align=3D"LEFT" style=3D"padding-left:10px"><font= | ||
face=3D"Arial, Verdana, Helvetica, sans-serif" size=3D"2"> 08:00 13/10/202= | ||
0 GMT</font></td> | ||
</tr> | ||
=20 | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2"><b> Service ID: </b></font></td> | ||
<td valign=3D"TOP" align=3D"LEFT" style=3D"padding-left:10px"><font= | ||
face=3D"Arial, Verdana, Helvetica, sans-serif" size=3D"2">111-AAA-11-11BB-= | ||
33333</font></td> | ||
</tr> | ||
=20 | ||
</tbody></table> | ||
<br> | ||
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0"> | ||
<tbody><tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2">Please note that all time stamps below will = | ||
appear in US Central time.<br><br></font></td> | ||
</tr> | ||
=20 | ||
=20 | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, H= | ||
elvetica, sans-serif" size=3D"2">- Update - There are no new updates.<br></= | ||
font></td> | ||
</tr> | ||
glennmatthews marked this conversation as resolved.
Show resolved
Hide resolved
|
||
=20 | ||
=20 | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, H= | ||
elvetica, sans-serif" size=3D"2"><br></font></td> | ||
</tr> | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2">Sincerely,</font></td> | ||
</tr> | ||
<tr> | ||
<td valign=3D"TOP" align=3D"LEFT"><font face=3D"Arial, Verdana, Hel= | ||
vetica, sans-serif" size=3D"2">Aqua Comms NOC</font></td> | ||
</tr> | ||
</tbody></table> | ||
</font> | ||
|
||
--000000000000015b7605ca799cf2-- |
15 changes: 15 additions & 0 deletions
15
tests/unit/data/aquacomms/aquacomms1_html_parser_result.json
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,15 @@ | ||
[ | ||
{ | ||
"circuits": [ | ||
{ | ||
"circuit_id": "111-AAA-11-11BB-33333", | ||
"impact": "OUTAGE" | ||
} | ||
], | ||
"end": 1602576000, | ||
"maintenance_id": "11111", | ||
"start": 1602540000, | ||
"status": "CONFIRMED", | ||
"summary": "There are no new updates." | ||
} | ||
] |
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,21 @@ | ||
[ | ||
{ | ||
"account": "999", | ||
"circuits": [ | ||
{ | ||
"circuit_id": "111-AAA-11-11BB-33333", | ||
"impact": "OUTAGE" | ||
} | ||
], | ||
"end": 1602576000, | ||
"maintenance_id": "11111", | ||
"organizer": "[email protected]", | ||
"provider": "aquacomms", | ||
"sequence": 1, | ||
"stamp": 1629998529, | ||
"start": 1602540000, | ||
"status": "CONFIRMED", | ||
"summary": "There are no new updates.", | ||
"uid": "0" | ||
} | ||
] |
6 changes: 6 additions & 0 deletions
6
tests/unit/data/aquacomms/aquacomms1_subject_parser_result.json
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,6 @@ | ||
[ | ||
{ | ||
"account": "999", | ||
"maintenance_id": "11111" | ||
} | ||
] |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.