Skip to content

Commit

Permalink
Merge pull request #300 from snitass/tata-parser-refactor
Browse files Browse the repository at this point in the history
use dt2ts instead of _parse_time static method
  • Loading branch information
chadell authored Nov 29, 2024
2 parents cd0175c + fef0d63 commit 6cbf7bc
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions circuit_maintenance_parser/parsers/tata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ def parse_html(self, soup: ResultSet) -> List[Dict]:
)
elif prev_lower in ("activity window (gmt)", "revised activity window (gmt)"):
start_end = curr.split("to")
data["start"] = self._parse_time(start_end[0])
data["end"] = self._parse_time(start_end[1])
data["start"] = self.dt2ts(datetime.strptime(start_end[0].strip(), "%Y-%m-%d %H:%M:%S %Z"))
data["end"] = self.dt2ts(datetime.strptime(start_end[1].strip(), "%Y-%m-%d %H:%M:%S %Z"))
elif "extended up to time window" in prev_lower:
if "gmt" in curr.lower():
data["end"] = self._parse_time(curr)
data["end"] = self.dt2ts(datetime.strptime(curr, "%Y-%m-%d %H:%M:%S %Z"))
prev = span.text.strip()

return [data]

@staticmethod
def _parse_time(string: str) -> int:
"""Convert YYYY-MM-DD HH:MM:SS GMT to epoch."""
return int((datetime.strptime(string.strip(), "%Y-%m-%d %H:%M:%S GMT") - datetime(1970, 1, 1)).total_seconds())


class SubjectParserTata(EmailSubjectParser):
"""Custom Parser for Email subject of Tata circuit maintenance notifications."""
Expand Down

0 comments on commit 6cbf7bc

Please sign in to comment.