diff --git a/api/ECNQueue.py b/api/ECNQueue.py index 4f0ebee..89c4d87 100644 --- a/api/ECNQueue.py +++ b/api/ECNQueue.py @@ -5,6 +5,7 @@ #------------------------------------------------------------------------------# import os, time, email, re, datetime from dateutil.parser import parse +from dateutil import tz from typing import Union import json @@ -284,7 +285,7 @@ def __parseSections(self) -> list: # Checks for a parse error and appends it, returning the sections list which stops the parsing if editInfo["type"] == "parse_error": sections.append(editInfo) - return sections + return self.__getSortedSections(sections) # Appends the edit dictionary to sections sections.append(editInfo) @@ -296,7 +297,7 @@ def __parseSections(self) -> list: # Checks for a parse error and appends it, returning the sections list which stops the parsing if replyToInfo["type"] == "parse_error": sections.append(replyToInfo) - return sections + return self.__getSortedSections(sections) # Appends the reply-to to sections sections.append(replyToInfo) @@ -307,7 +308,7 @@ def __parseSections(self) -> list: if statusInfo["type"] == "parse_error": sections.append(statusInfo) - return sections + return self.__getSortedSections(sections) # Appends the status to sections sections.append(statusInfo) @@ -318,12 +319,15 @@ def __parseSections(self) -> list: if replyFromInfo["type"] == "parse_error": sections.append(replyFromInfo) - return sections + return self.__getSortedSections(sections) # Appends the replyFrom to sections sections.append(replyFromInfo) - - return sections + + sortedSections = self.__getSortedSections(sections) + + return sortedSections + #return sections def __directoryParsing(self, directoryStartLine: int) -> dict: """Returns a dictionary with directory information @@ -965,6 +969,46 @@ def __errorParsing(self, line: str, lineNum: int, expectedSyntax: str) -> dict: # returns the error dictionary return errorDictionary + def __getSortedSections(self, sectionsList: list) -> list: + """Sorts the sections chronologically by datetime + + Example: + [example] need to do + + Args: + sections (list): the list of sections to be sorted + + Returns: + list: a list of sections sorted by datetime + """ + sectionsLength = len(sectionsList) + sortedSections = [] + oldestSection = {} + + while len(sortedSections) < sectionsLength: + + for iteration, currentSection in enumerate(sectionsList): + + if currentSection["type"] == "directory_information": + sortedSections.append(currentSection) + sectionsList.remove(currentSection) + break + + if iteration == 0: + oldestSection = currentSection + + #datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S.%f') + + elif parse(currentSection["datetime"]) < parse(oldestSection["datetime"]): + oldestSection = currentSection + + if iteration == len(sectionsList) - 1: + sortedSections.append(oldestSection) + sectionsList.remove(oldestSection) + + return sortedSections + + def __isLocked(self) -> Union[str, bool]: """Returns a string info about the lock if true and a bool False if false @@ -1065,7 +1109,8 @@ def __getFormattedDate(self, date: str) -> str: str: Properly formatted date/time recieved or empty string. """ try: - parsedDate = parse(date) + parsedDate = parse(date, default= datetime.datetime(2017, 10, 13, tzinfo=tz.gettz('EDT'))) + #parsedDate = parse(date, default= datetime.datetime(2017, 10, 13, tzinfo=datetime.timezone.) except: return "" diff --git a/api/api.py b/api/api.py index 29a4492..1e91580 100644 --- a/api/api.py +++ b/api/api.py @@ -52,7 +52,13 @@ def get(self, queue: str) -> str: Returns: str: JSON representation of the queue requested. """ - return ECNQueue.Queue(queue).toJson() + queues_requested = queue.split("+") + + queues = [] + for queue in queues_requested: + queues.append(ECNQueue.Queue(queue).toJson()) + + return queues @@ -62,4 +68,4 @@ def get(self, queue: str) -> str: if __name__ == "__main__": - app.run() \ No newline at end of file + app.run()