Skip to content

Commit b967609

Browse files
scetronchadell
andauthored
Fix Equinix Parser (#143)
* Add parsing notes. Parse Year and add to ts. * Update poetry lock * Upgrade to Python 3.6.2 Co-authored-by: Christian Adell <[email protected]>
1 parent dbf52af commit b967609

File tree

9 files changed

+562
-373
lines changed

9 files changed

+562
-373
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
## v2.0.9
44

5+
### Changed
6+
7+
- #143 - Minimum Python version changed from `3.6.1` to `3.6.2`
8+
59
### Fixed
610

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

1015
## v2.0.8 - 2021-12-09
1116

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/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)