Skip to content

Commit

Permalink
Merge pull request #144 from networktocode/release-v2.1.0
Browse files Browse the repository at this point in the history
Release v2.1.0
  • Loading branch information
chadell authored May 13, 2022
2 parents b7e90be + d5b94eb commit ffea065
Show file tree
Hide file tree
Showing 18 changed files with 1,507 additions and 397 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## v2.1.0 - 2022-05-13

### Changed

- #143 - Minimum Python version changed from `3.6.1` to `3.6.2`

### Fixed

- #132 - Handle alternate "has been cancelled" text in Telstra notifications.
- #134 - Handle Zayo "RESCHEDULE" notifications.
- #143 - Fix Equinix parser not taking year into account

## v2.0.8 - 2021-12-09

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion circuit_maintenance_parser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main(provider_type, data_file, data_type, verbose):

if data_type == "email":
if str.lower(data_file[-3:]) == "eml":
with open(data_file) as email_file:
with open(data_file, encoding="utf-8") as email_file:
msg = email.message_from_file(email_file)
data = NotificationData.init_from_emailmessage(msg)
else:
Expand Down
17 changes: 14 additions & 3 deletions circuit_maintenance_parser/parsers/equinix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def parse_html(self, soup: ResultSet) -> List[Dict]:
Returns:
Dict: The data dict containing circuit maintenance data.
"""
data: Dict[str, Any] = {"circuits": list()}
data: Dict[str, Any] = {"circuits": []}

impact = self._parse_b(soup.find_all("b"), data)
self._parse_table(soup.find_all("th"), data, impact)
Expand Down Expand Up @@ -54,18 +54,29 @@ def _parse_b(self, b_elements, data):
impact (Status object): impact of the maintenance notification (used in the parse table function to assign an impact for each circuit).
"""
impact = None
start_year = 0
end_year = 0
for b_elem in b_elements:
if "SPAN:" in b_elem.text:
# Formated in DAY MONTH YEAR
# *SPAN: 02-JUL-2021 - 03-JUL-2021*
raw_year_span = b_elem.text.strip().split()
start_year = raw_year_span[1].split("-")[-1]
end_year = raw_year_span[-1].split("-")[-1]
if "UTC:" in b_elem:
raw_time = b_elem.next_sibling
# for non english equinix notifications
# english section is usually at the bottom
# this skips the non english line at the top
if not self._isascii(raw_time):
continue

# Expected Format *UTC:* FRIDAY, 02 JUL 10:00 - FRIDAY, 02 JUL 15:00
# Note this detailed time does not contain the year..
start_end_time = raw_time.split("-")
if len(start_end_time) == 2:
data["start"] = self.dt2ts(parser.parse(raw_time.split("-")[0].strip()))
data["end"] = self.dt2ts(parser.parse(raw_time.split("-")[1].strip()))
data["start"] = self.dt2ts(parser.parse(start_end_time[0].strip() + f" {start_year}"))
data["end"] = self.dt2ts(parser.parse(start_end_time[1].strip() + f" {end_year}"))
# all circuits in the notification share the same impact
if "IMPACT:" in b_elem:
impact_line = b_elem.next_sibling
Expand Down
13 changes: 7 additions & 6 deletions circuit_maintenance_parser/parsers/telstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ def parse_html(self, soup):
self.parse_tables(soup.find_all("table"), data)
return [data]

def parse_tables(self, tables: ResultSet, data: Dict):
def parse_tables(self, tables: ResultSet, data: Dict): # pylint: disable=too-many-locals
"""Parse Table tag."""
for table in tables:
for td_element in table.find_all("td"):
# TODO: We should find a more consistent way to parse the status of a maintenance note
if "maintenance has been scheduled" in td_element.text.lower():
td_text = td_element.text.lower()
if "maintenance has been scheduled" in td_text:
data["status"] = Status("CONFIRMED")
elif "this is a reminder notification to notify that a planned maintenance" in td_element.text.lower():
elif "this is a reminder notification to notify that a planned maintenance" in td_text:
data["status"] = Status("CONFIRMED")
elif "has been completed" in td_element.text.lower():
elif "has been completed" in td_text:
data["status"] = Status("COMPLETED")
elif "has been amended" in td_element.text.lower():
elif "has been amended" in td_text:
data["status"] = Status("RE-SCHEDULED")
elif "has been withdrawn" in td_element.text.lower():
elif "has been withdrawn" in td_text or "has been cancelled" in td_text:
data["status"] = Status("CANCELLED")
else:
continue
Expand Down
2 changes: 2 additions & 0 deletions circuit_maintenance_parser/parsers/zayo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def parse_html(self, soup):
data["status"] = Status("IN-PROCESS")
elif "has been completed" in text or "has closed" in text:
data["status"] = Status("COMPLETED")
elif "has rescheduled" in text:
data["status"] = Status("RE-SCHEDULED")

return [data]

Expand Down
2 changes: 1 addition & 1 deletion circuit_maintenance_parser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def timezone(cls): # pylint: disable=no-self-argument
def db_location(cls): # pylint: disable=no-self-argument
"""Load the locations DB from CSV into a Dict."""
if not cls._db_location:
with open(os.path.join(dirname, "data", "worldcities.csv")) as csvfile:
with open(os.path.join(dirname, "data", "worldcities.csv"), encoding="utf-8") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
# Index by city and country
Expand Down
Loading

0 comments on commit ffea065

Please sign in to comment.