Skip to content

Commit

Permalink
Merge pull request #1 from guusbosman/main
Browse files Browse the repository at this point in the history
Ignoring log lines without dates, or with empty dates
  • Loading branch information
uoodsq authored Dec 13, 2023
2 parents c17f0f5 + 299df43 commit 9074af5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion moto/modem_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ def from_response(cls, response: str) -> Generator[Self, None, None]:
Parse a raw log string into a generator of ModemLog objects.
"""
for line in response.split("}-{"):
yield cls.from_line(line)
modemlog = cls.from_line(line)
if modemlog is not None:
yield modemlog


@classmethod
def from_line(cls, line: str) -> Self:
"""
Parse a single log line into a ModemLog object.
"""
if "Time Not Established" in line:
return None
if "\n" not in line:
return None

timestamp_str, line = line.split("\n", 1)
timestamp = parse_datetime(timestamp_str.replace("^", " "))
timestamp.replace(tzinfo=gettz(os.getenv("TZ", "UTC")))
Expand Down

0 comments on commit 9074af5

Please sign in to comment.