Skip to content

Commit

Permalink
Added assignment parsing helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Daniel Bennett committed Oct 20, 2020
1 parent b783497 commit acd0733
Showing 1 changed file with 70 additions and 54 deletions.
124 changes: 70 additions & 54 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,90 +185,66 @@ 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)

# 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit acd0733

Please sign in to comment.