|
5 | 5 | import calendar
|
6 | 6 | import datetime
|
7 | 7 | import quopri
|
| 8 | +import hashlib |
8 | 9 | from typing import Dict, List
|
9 | 10 | from email.utils import parsedate_tz, mktime_tz
|
10 |
| -import hashlib |
| 11 | +from dateutil.parser import isoparse |
11 | 12 |
|
12 | 13 | import bs4 # type: ignore
|
13 | 14 | from bs4.element import ResultSet # type: ignore
|
@@ -297,15 +298,15 @@ class LLM(Parser):
|
297 | 298 | _data_types = PrivateAttr(["text/html", "html", "text/plain"])
|
298 | 299 |
|
299 | 300 | _llm_question = """Please, could you extract a JSON form without any other comment,
|
300 |
| - with the following JSON schema (timestamps in EPOCH and taking into account the GMT offset): |
| 301 | + with the following JSON schema (start and end times are datetime objects and should be displayed in UTC): |
301 | 302 | {
|
302 | 303 | "type": "object",
|
303 | 304 | "properties": {
|
304 | 305 | "start": {
|
305 |
| - "type": "int", |
| 306 | + "type": "datetime", |
306 | 307 | },
|
307 | 308 | "end": {
|
308 |
| - "type": "int", |
| 309 | + "type": "datetime", |
309 | 310 | },
|
310 | 311 | "account": {
|
311 | 312 | "type": "string",
|
@@ -408,6 +409,17 @@ def _get_circuit_ids(self, generated_json: dict, impact: Impact):
|
408 | 409 |
|
409 | 410 | return circuits
|
410 | 411 |
|
| 412 | + def _convert_str_datetime_to_epoch(self, time_str): |
| 413 | + try: |
| 414 | + # Using isoparse for flexible ISO8601 parsing |
| 415 | + time_dt = isoparse(time_str).astimezone(datetime.timezone.utc) |
| 416 | + epoch_time = int(time_dt.timestamp()) |
| 417 | + return epoch_time |
| 418 | + |
| 419 | + except Exception as error_received: |
| 420 | + logger.error("Error parsing dates: %s", error_received) |
| 421 | + raise ParserError from error_received |
| 422 | + |
411 | 423 | def _get_start(self, generated_json: dict):
|
412 | 424 | """Method to get the Start Time."""
|
413 | 425 | return generated_json[self.get_key_with_string(generated_json, "start")]
|
@@ -460,6 +472,10 @@ def parse_content(self, content):
|
460 | 472 | if not generated_json:
|
461 | 473 | return []
|
462 | 474 |
|
| 475 | + if generated_json.get("start") and generated_json.get("end"): |
| 476 | + generated_json["start"] = self._convert_str_datetime_to_epoch(generated_json["start"]) |
| 477 | + generated_json["end"] = self._convert_str_datetime_to_epoch(generated_json["end"]) |
| 478 | + |
463 | 479 | impact = self._get_impact(generated_json)
|
464 | 480 |
|
465 | 481 | data = {
|
|
0 commit comments