Skip to content

Commit ffea065

Browse files
authored
Merge pull request #144 from networktocode/release-v2.1.0
Release v2.1.0
2 parents b7e90be + d5b94eb commit ffea065

18 files changed

+1507
-397
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## v2.1.0 - 2022-05-13
4+
5+
### Changed
6+
7+
- #143 - Minimum Python version changed from `3.6.1` to `3.6.2`
8+
9+
### Fixed
10+
11+
- #132 - Handle alternate "has been cancelled" text in Telstra notifications.
12+
- #134 - Handle Zayo "RESCHEDULE" notifications.
13+
- #143 - Fix Equinix parser not taking year into account
14+
315
## v2.0.8 - 2021-12-09
416

517
### Fixed

circuit_maintenance_parser/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main(provider_type, data_file, data_type, verbose):
3131

3232
if data_type == "email":
3333
if str.lower(data_file[-3:]) == "eml":
34-
with open(data_file) as email_file:
34+
with open(data_file, encoding="utf-8") as email_file:
3535
msg = email.message_from_file(email_file)
3636
data = NotificationData.init_from_emailmessage(msg)
3737
else:

circuit_maintenance_parser/parsers/equinix.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def parse_html(self, soup: ResultSet) -> List[Dict]:
2121
Returns:
2222
Dict: The data dict containing circuit maintenance data.
2323
"""
24-
data: Dict[str, Any] = {"circuits": list()}
24+
data: Dict[str, Any] = {"circuits": []}
2525

2626
impact = self._parse_b(soup.find_all("b"), data)
2727
self._parse_table(soup.find_all("th"), data, impact)
@@ -54,18 +54,29 @@ def _parse_b(self, b_elements, data):
5454
impact (Status object): impact of the maintenance notification (used in the parse table function to assign an impact for each circuit).
5555
"""
5656
impact = None
57+
start_year = 0
58+
end_year = 0
5759
for b_elem in b_elements:
60+
if "SPAN:" in b_elem.text:
61+
# Formated in DAY MONTH YEAR
62+
# *SPAN: 02-JUL-2021 - 03-JUL-2021*
63+
raw_year_span = b_elem.text.strip().split()
64+
start_year = raw_year_span[1].split("-")[-1]
65+
end_year = raw_year_span[-1].split("-")[-1]
5866
if "UTC:" in b_elem:
5967
raw_time = b_elem.next_sibling
6068
# for non english equinix notifications
6169
# english section is usually at the bottom
6270
# this skips the non english line at the top
6371
if not self._isascii(raw_time):
6472
continue
73+
74+
# Expected Format *UTC:* FRIDAY, 02 JUL 10:00 - FRIDAY, 02 JUL 15:00
75+
# Note this detailed time does not contain the year..
6576
start_end_time = raw_time.split("-")
6677
if len(start_end_time) == 2:
67-
data["start"] = self.dt2ts(parser.parse(raw_time.split("-")[0].strip()))
68-
data["end"] = self.dt2ts(parser.parse(raw_time.split("-")[1].strip()))
78+
data["start"] = self.dt2ts(parser.parse(start_end_time[0].strip() + f" {start_year}"))
79+
data["end"] = self.dt2ts(parser.parse(start_end_time[1].strip() + f" {end_year}"))
6980
# all circuits in the notification share the same impact
7081
if "IMPACT:" in b_elem:
7182
impact_line = b_elem.next_sibling

circuit_maintenance_parser/parsers/telstra.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ def parse_html(self, soup):
2222
self.parse_tables(soup.find_all("table"), data)
2323
return [data]
2424

25-
def parse_tables(self, tables: ResultSet, data: Dict):
25+
def parse_tables(self, tables: ResultSet, data: Dict): # pylint: disable=too-many-locals
2626
"""Parse Table tag."""
2727
for table in tables:
2828
for td_element in table.find_all("td"):
2929
# TODO: We should find a more consistent way to parse the status of a maintenance note
30-
if "maintenance has been scheduled" in td_element.text.lower():
30+
td_text = td_element.text.lower()
31+
if "maintenance has been scheduled" in td_text:
3132
data["status"] = Status("CONFIRMED")
32-
elif "this is a reminder notification to notify that a planned maintenance" in td_element.text.lower():
33+
elif "this is a reminder notification to notify that a planned maintenance" in td_text:
3334
data["status"] = Status("CONFIRMED")
34-
elif "has been completed" in td_element.text.lower():
35+
elif "has been completed" in td_text:
3536
data["status"] = Status("COMPLETED")
36-
elif "has been amended" in td_element.text.lower():
37+
elif "has been amended" in td_text:
3738
data["status"] = Status("RE-SCHEDULED")
38-
elif "has been withdrawn" in td_element.text.lower():
39+
elif "has been withdrawn" in td_text or "has been cancelled" in td_text:
3940
data["status"] = Status("CANCELLED")
4041
else:
4142
continue

circuit_maintenance_parser/parsers/zayo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def parse_html(self, soup):
5555
data["status"] = Status("IN-PROCESS")
5656
elif "has been completed" in text or "has closed" in text:
5757
data["status"] = Status("COMPLETED")
58+
elif "has rescheduled" in text:
59+
data["status"] = Status("RE-SCHEDULED")
5860

5961
return [data]
6062

circuit_maintenance_parser/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def timezone(cls): # pylint: disable=no-self-argument
4747
def db_location(cls): # pylint: disable=no-self-argument
4848
"""Load the locations DB from CSV into a Dict."""
4949
if not cls._db_location:
50-
with open(os.path.join(dirname, "data", "worldcities.csv")) as csvfile:
50+
with open(os.path.join(dirname, "data", "worldcities.csv"), encoding="utf-8") as csvfile:
5151
reader = csv.DictReader(csvfile)
5252
for row in reader:
5353
# Index by city and country

0 commit comments

Comments
 (0)