diff --git a/api/ECNQueue.py b/api/ECNQueue.py index af982fe..eb6e78d 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -185,22 +185,20 @@ def __parseSections(self) -> list: contentStart = self.__getHeaderBoundary() + 1 contentEnd = len(self.__rawItem) - 1 - #directoryInfo = {"type": "directoryInformation"} - initialMessageSection = True - - # Delimiter info - delimiters = [ - {"name": "edit", "pattern": "*** Edited"}, - {"name": "status", "pattern": "*** Status"}, - {"name": "replyToUser", "pattern": "*** Replied"}, - {"name": "replyFromUser", "pattern": "=== "}, - ] + # List of assignments for the item + assignementLsit = self.__assignmentParsing(contentStart) + # Appends each assignment individually to sections + for assignment in assignementLsit: + sections.append(assignment) + # Checks for Directory Identifiers if self.__rawItem[contentStart] == "\n" and self.__rawItem[contentStart + 1].startswith("\t"): + directoryStartLine = contentStart + 1 + # Parses the directory information and returns a dictionary of directory values - directoryInfo = self.__directoryParsing(contentStart + 1) + directoryInfo = self.__directoryParsing(directoryStartLine) # Appends Directory Information into the sections array sections.append(directoryInfo) @@ -208,67 +206,45 @@ def __parseSections(self) -> list: # Sets the initial message start to the next line after all directory lines and newlines contentStart = contentStart + len(directoryInfo) + 1 + # The start line, type, and end line for item events sectionBoundaries = [] + # Delimiter info + delimiters = [ + {"name": "edit", "pattern": "*** Edited"}, + {"name": "status", "pattern": "*** Status"}, + {"name": "replyToUser", "pattern": "*** Replied"}, + {"name": "replyFromUser", "pattern": "=== "}, + ] + + # Signifies that there is an initial message to parse + initialMessageSection = True + # Parses the entire contents of the message, stores everything before any delimiter as the initial message - # and the line number of any delimiters + # and the line number of any delimiters as well as the type for lineNumber in range(contentStart, contentEnd + 1): line = self.__rawItem[lineNumber] + # Looks for a starting delimiter and explicity excludes the reply-from-user ending delimiter if line.startswith("***") or line.startswith("===") and not line.startswith("===="): + + # Sets the delimiter type based on the pattern within the delimiters list for delimiter in delimiters: if line.startswith(delimiter["pattern"]): - sectionBoundaries.append({"start": lineNumber, "type": delimiter["name"]}) break - # Signifies that the inital message has been completely parsed - initialMessageSection = False + # If a starting delimiter was encountered, then there is no initial message + if initialMessageSection: + initialMessageSection = False elif initialMessageSection == True: - - # Delimiter not encountered yet, so append line to initial message list + # Delimiter not encountered yet, so append initial message starting line as the current lin number sectionBoundaries.append({"start": lineNumber, "type": "initial_message"}) - initialMessageSection = False - # Assignment Information - assignedBy = "" - assignedDateTime = "" - assignedTo = "" - - # Parses the header looking for assignment delimeters and stores info into their respective variables - for headerContent in range(0, contentStart): - - line = self.__rawItem[headerContent] - - # Gets who the Item was assigned to - if line.startswith("Assigned-To: "): - - assignedTo = (re.search("(?<=Assigned-To: )(.*)", line)).group() - - # Gets the date the Item was assigned - elif line.startswith("Assigned-To-Updated-Time: "): - - dateFromLine = (re.search("(?<=Assigned-To-Updated-Time: )(.*)", line)).group() - - assignedDateTime = self.__getFormattedDate(dateFromLine) - - # Gets who assigned the Item - elif line.startswith("Assigned-To-Updated-By: "): - - assignedBy = (re.search("(?<=Assigned-To-Updated-By: )(.*)", line)).group() - - # Appends the assignment to the sections list - sections.append( - {"type": "assignment", - "datetime": assignedDateTime, - "by": assignedBy, - "to": assignedTo} - ) - sectionBoundaries.append({"start": contentEnd + 1}) # Sets the end of the section boundary to the begining of the next section boundary @@ -415,7 +391,47 @@ def __directoryParsing(self, directoryStartLine: int) -> dict: # Returns the directory information dictionary return directoryInformation - + + def __assignmentParsing(self, contentStart) -> list: + assignmentList =[] + + # Assignment Information + assignedBy = "" + assignedDateTime = "" + assignedTo = "" + + # Parses the header looking for assignment delimeters and stores info into their respective variables + for headerContent in range(0, contentStart): + + line = self.__rawItem[headerContent] + + # Gets who the Item was assigned to + if line.startswith("Assigned-To: "): + + assignedTo = (re.search("(?<=Assigned-To: )(.*)", line)).group() + + # Gets the date the Item was assigned + elif line.startswith("Assigned-To-Updated-Time: "): + + dateFromLine = (re.search("(?<=Assigned-To-Updated-Time: )(.*)", line)).group() + + assignedDateTime = self.__getFormattedDate(dateFromLine) + + # Gets who assigned the Item + elif line.startswith("Assigned-To-Updated-By: "): + + assignedBy = (re.search("(?<=Assigned-To-Updated-By: )(.*)", line)).group() + + # Appends the assignment to the sections list + assignmentList.append( + {"type": "assignment", + "datetime": assignedDateTime, + "by": assignedBy, + "to": assignedTo} + ) + + return assignmentList + def __initialMessageParsing(self, content: list) -> dict: """Returns a dictionary with initial message information