Skip to content

Commit

Permalink
Remove getContent function /c no longer neede
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Campbell committed Oct 29, 2020
1 parent fea27fd commit 202e04c
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ class Item:
"""

def __init__(self, queue: str, number: int) -> None:

self.queue = queue
try:
self.number = int(number)
except ValueError:
raise ValueError("Could not convert \"" + number + "\" to an integer")
#self.number = number
raise ValueError(" Could not convert \"" + number + "\" to an integer")

self.__path = "/".join([queueDirectory, self.queue, str(self.number)])
self.lastUpdated = self.__getLastUpdated()
Expand All @@ -107,6 +105,7 @@ def __init__(self, queue: str, number: int) -> None:
self.building = self.__getMostRecentHeaderByType("Building")
self.dateReceived = self.__getFormattedDate(self.__getMostRecentHeaderByType("Date"))

# TODO: Autopopulate jsonData w/ __dir__() command. Exclude `^_` and `jsonData`.
self.jsonData = {
"queue": self.queue,
"number": self.number,
Expand Down Expand Up @@ -135,6 +134,7 @@ def __getLastUpdated(self) -> str:
Returns:
str: last modified time of item reported by the filesystem in mm-dd-yy hh:mm am/pm format.
"""
# TODO: Simplify this code block by allowing __getFormattedDate to accept milliseconds since the epoch.
unixTime = os.path.getmtime(self.__path)
formattedTime = time.strftime('%m-%d-%y %I:%M %p', time.localtime(unixTime))
return self.__getFormattedDate(formattedTime)
Expand Down Expand Up @@ -195,7 +195,8 @@ def __parseHeaders(self) -> list:

headerString += line

message = email.message_from_string(headerString + "".join(self.__getContent()))
# message = email.message_from_string(headerString + "".join(self.__getContent()))
message = email.message_from_string(headerString)

headers = []
for key in message.keys():
Expand All @@ -205,26 +206,6 @@ def __parseHeaders(self) -> list:

# TODO: Implement attachment parsing

def __getContent(self) -> list:
"""Returns a dictionary of lines of the item body.
Example:
"Hello. I need help.\\n\\n*** Status updated by: campb303 at: 6/23/2020 13:26:55 ***\\nDont Delete" becomes
[
"Hello. I need help.\\n",
"\\n",
"*** Status updated by: campb303 at: 6/23/2020 13:26:55 ***\\n",
"Don't Delete",
]
Returns:
list: Lines of the body item.
"""
contentStart = self.__getHeaderBoundary() + 1
contentEnd = len(self.__rawItem) - 1
return self.__rawItem[ contentStart : contentEnd ]


def __parseSections(self) -> list:
# List of all item events
sections = []
Expand Down Expand Up @@ -1253,3 +1234,9 @@ def getQueues() -> list:
queues.append(Queue(file))

return queues

if __name__ == "__main__":
start = time.time()
queues = getQueues()
end = time.time()
print(f'Fetching all queues took {end - start}s')

0 comments on commit 202e04c

Please sign in to comment.