From 429213f4664a3f5bf06c8a28edcc5c8c3521838d Mon Sep 17 00:00:00 2001 From: Jacob Daniel Bennett Date: Mon, 5 Oct 2020 08:50:56 -0400 Subject: [PATCH] Update dictionary keys for each parsed section per github issue #2 --- api/ECNQueue.py | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 8df35cf..5cdc431 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -268,8 +268,22 @@ def __parseSections(self) -> list: # Formats the initial message date to UTC initialMessageFormattedDate = self.__getFormattedDate(initialMessageDateStr) + # Stores list of dictionaries for the recipients of the initial message + initialMessageRecipientsSection = [] + + # Parses the header looking for recipients of the initial message and stores it in a list of tuples + initialMessageRecipientsList = email.utils.getaddresses([self.__getMostRecentHeaderByType("To")]) + + # Parses the CC list and stores the cc recipient information in a list of dictionaries + for recipients in initialMessageRecipientsList: + + initialMessageRecipientsSection.append( + {"name": recipients[0], + "email": recipients[1]} + ) + # Stores list of dictionaries for CC information - initialMessageCCSection =[] + initialMessageCCSection = [] # Parses the header looking for CC recipients of the initial message and stores it in a list of tuples initialMessageCCList = email.utils.getaddresses([self.__getMostRecentHeaderByType("CC")]) @@ -284,11 +298,12 @@ def __parseSections(self) -> list: # Appends all initial message information to the sections array sections.append( - {"type": "initialMessage", + {"type": "initial_message", "datetime": initialMessageFormattedDate, - "userName": self.__parseFromData(data="userName"), - "userEmail": self.__parseFromData(data="userEmail"), - "ccRecipients": initialMessageCCSection, + "from_name": self.__parseFromData(data="userName"), + "user_email": self.__parseFromData(data="userEmail"), + "to": initialMessageRecipientsSection, + "cc": initialMessageCCSection, "content": initialMessageContent} ) @@ -321,9 +336,9 @@ def __parseSections(self) -> list: # Appends the assignment to the sections list sections.append( - {"type": "assign", - "by": assignedBy, + {"type": "assignment", "datetime": assignedDateTime, + "by": assignedBy, "to": assignedTo} ) @@ -488,8 +503,8 @@ def __editParsing(self, line: str) -> dict: editInfo = { "type": "edit", - "by": editedBy, "datetime": formattedDateTime, + "by": editedBy, "content": "" } @@ -515,9 +530,9 @@ def __replyToParsing(self, line: str) -> dict: formattedDateTime = self.__getFormattedDate(dateTimeString) replyInfo = { - "type": "replyToUser", - "by": repliedBy, + "type": "reply_to_user", "datetime": formattedDateTime, + "by": repliedBy, "content": "" } @@ -544,8 +559,8 @@ def __statusParsing(self, line: str) -> dict: statusInfo = { "type": "status", - "by": updatedBy, "datetime": formattedDateTime, + "by": updatedBy, "content": "" } @@ -642,13 +657,13 @@ def __userReplyParsing(self, replyContent: list) -> dict: replyContent = self.__getFormattedMessageContent(replyContent) replyFromInfo = { - "type": "replyFromUser", + "type": "reply_from_user", "datetime": formattedDateTime, - "subject": subject, - "userName": repliedByName, - "userEmail": repliedByEmail, - "content": replyContent, - "ccRecipients": ccRecipientsList + #"subject": subject, + "from_name": repliedByName, + "from_email": repliedByEmail, + "cc": ccRecipientsList, + "content": replyContent } return replyFromInfo