From 58381c5c73ed6298625664a8876cb7c601b779cc Mon Sep 17 00:00:00 2001 From: Jacob Daniel Bennett Date: Tue, 15 Sep 2020 10:03:12 -0400 Subject: [PATCH] Partial functionality added for parsing reply from user section --- api/ECNQueue.py | 75 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 976f770..983b179 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -272,6 +272,8 @@ def __parseSections(self) -> list: "time": formattedTime, "content": sectionContent,} ) + + sectionContent.remove(line) elif sectionType == "replyToUser": formattedDate = "" @@ -326,19 +328,76 @@ def __parseSections(self) -> list: "time": formattedTime, "content": sectionContent} ) + #sectionContent.remove(line) + + #elif sectionType == "": + elif sectionType == "replyFromUser": + + #replyMetaDataDelimiters = ["Subject: ", "From: ", "Date: "] - elif sectionType == "": - #elif sectionType == "replyFromUser": formattedDate = "" formattedTime = "" - repliedBy = "" - + repliedByName = "" + repliedByEmail = "" + subject = "" + ccRecipientsList = [] + ccRecipientDict = {} + + """ + ccRecipientDict Format: + ccRecipientDict = { + "Name": Name + "Email": Email + } + """ + + lineNum = 0 + linesToBeDeleted = [0] + + for items in sectionContent: + if items.startswith("Subject: "): + subject = (re.search("(?<=Subject: )(.*)", items)).group() + linesToBeDeleted.append(lineNum) + + elif items.startswith("From: "): + repliedByEmail = (re.search("(?<=From: )(.*)(?= <)", items)).group() + repliedByName = (re.search("(?<= <)(.*)(?=>)", items)).group() + linesToBeDeleted.append(lineNum) + + elif items.startswith("Date: "): + dateStr = (re.search("(?<=Date: )(.*)", items)).group() + + try: + dateObject = parse(dateStr) + formattedDate = dateObject.strftime("%Y-%m-%dT%H:%M:%S%z") + formattedTime = dateObject.strftime("%H:%M:%S%z") + linesToBeDeleted.append(lineNum) + except: + formattedDate = "invalid" + formattedTime = "Invalid" + + elif items.startswith("Cc: "): + ccString = (re.search("(?<=Cc: )(.*)", items)).group() + ####################################################################################### + + lineNum = lineNum + 1 + + for lineNumbers in sorted(linesToBeDeleted, reverse=True): + sectionContent.pop(lineNumbers) #parses for the author of the status change, which is located between the "*** Status updated by: " and " at:" substrings - updatedBy = (re.search("(?<=\*{3} Status updated by: )(.*)(?= at:)", line)).group() + #updatedBy = (re.search("(?<=\*{3} Status updated by: )(.*)(?= at:)", line)).group() #parses for the date and time of the status change, which is located between the " at: " and "***\n" substrings - dateTimeString = (re.search("(?<= at: )(.*)(?= \*\*\*\n)", line)).group() - + #dateTimeString = (re.search("(?<= at: )(.*)(?= \*\*\*\n)", line)).group() + sections.append( + {"type": sectionType, + "date": formattedDate, + "time": formattedTime, + "subject": subject, + "userName": repliedByName, + "userEmail": repliedByEmail, + "content": sectionContent} + ) else: sections.append( @@ -522,5 +581,5 @@ def getQueues() -> list: return queues if __name__ == "__main__": - item = Item("ce", 11) + item = Item("ce", 100) print()