From 0da7774c9b85827cf77a827f651fb24b672c5966 Mon Sep 17 00:00:00 2001 From: Jacob Daniel Bennett Date: Mon, 28 Sep 2020 11:37:35 -0400 Subject: [PATCH] Directory Parsing now checks for a \tName delimiter before assuming a newline after header info denotes directory info --- api/ECNQueue.py | 55 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 8caaff0..77b4d50 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -185,11 +185,23 @@ def __parseSections(self) -> list: initialMessageContent = [] endInitialMessage = False - if self.__rawItem[contentStart] == "\n" : + # Checks for Directory Identifiers + if self.__rawItem[contentStart] == "\n" and self.__rawItem[contentStart + 1].startswith("\tName:"): + + # List of lines in the directory info rawDirectoryInfo = self.__rawItem[contentStart + 1: contentStart + 13] - directoryInfo["content"] = self.__directoryParsing(rawDirectoryInfo) + + # Parses the directory information and returns a dictionary of directory values + directoryInfo["content"] = self.__directoryParsing(contentStart + 1) + + # Sets the initial message start to the next line after all directory lines and newlines contentStart = contentStart + 14 + else: + + # Initialize an empty dictionary for content + directoryInfo["content"] = {} + # Appends Directory Information into the sections array sections.append(directoryInfo) @@ -355,6 +367,9 @@ def __parseSections(self) -> list: # Returns a dictionary with edit information editInfo = self.__editParsing(line) + # Remove the delimiter String + sectionContent.remove(line) + # Appends content of the edit message to the dictionary editInfo["content"] = sectionContent @@ -403,7 +418,7 @@ def __parseSections(self) -> list: return sections - def __directoryParsing(self, directoryContent: list) -> dict: + def __directoryParsing(self, directoryStartLine: int) -> dict: """Returns a dictionary with directory information Returns: dictionary: @@ -421,17 +436,28 @@ def __directoryParsing(self, directoryContent: list) -> dict: "Subject": subject """ directoryInformation = {} + + directoryEndingLine = directoryStartLine + while directoryEndingLine - directoryStartLine <= 11: + + info = self.__rawItem[directoryEndingLine] - for info in directoryContent: - strippedInfo = info.strip() - try: - key, value = strippedInfo.split(": ") - except: - key, value = strippedInfo.split(":") + if info == "\n": + + break - directoryInformation[key] = value + else: + strippedInfo = info.strip() + try: + key, value = strippedInfo.split(": ") + except: + key, value = strippedInfo.split(":") + + directoryInformation[key] = value + directoryEndingLine = directoryEndingLine + 1 return directoryInformation + def __editParsing(self, line: str) -> dict: """Returns a dictionary with edit information @@ -778,4 +804,11 @@ def getQueues() -> list: if isDirectory and isValid: queues.append(Queue(file)) - return queues \ No newline at end of file + return queues + +if __name__ == "__main__": + item = Item("ce", 100) + print() +# for queue in getQueues(): +# for item in queue.items: +# print(f"${item.queue} ${item.number}") \ No newline at end of file