Skip to content

Enhancement date parsing for header #48

Merged
merged 6 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#------------------------------------------------------------------------------#
# Imports
#------------------------------------------------------------------------------#
import os, time, email, re
import os, time, email, re, datetime
from dateutil.parser import parse
from typing import Union
import json

Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(self, queue: str, number: int) -> None:
self.priority = self.__getMostRecentHeaderByType("Priority")
self.department = self.__getMostRecentHeaderByType("Department")
self.building = self.__getMostRecentHeaderByType("Building")
self.dateReceived = self.__getMostRecentHeaderByType("Date")
self.dateReceived = self.__getParsedDate(self.__getMostRecentHeaderByType("Date"))

self.jsonData = {
"queue": self.queue,
Expand Down Expand Up @@ -264,6 +265,23 @@ def __getAssignedTo(self) -> str:
"""
assignedTo = self.__getMostRecentHeaderByType("Assigned-To")
return assignedTo

def __getFormattedDate(self, date: str) -> str:
"""Returns the date/time formatted as RFC 8601 YYYY-MM-DDTHH:MM:SS+00:00.
Returns empty string if the string argument passed to the function is not a datetime.
See: https://en.wikipedia.org/wiki/ISO_8601
Returns:
str: Properly formatted date/time recieved or empty string.
"""
try:
parsedDate = parse(date)
except:
return ""

parsedDateString = parsedDate.strftime("%Y-%m-%dT%H:%M:%S%z")

return parsedDateString

def toJson(self) -> dict:
"""Returns a JSON safe representation of the item.
Expand Down
31 changes: 31 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
aniso8601==8.0.0
astroid==2.4.2
attrs==20.1.0
click==7.1.2
Flask==1.1.2
Flask-RESTful==0.3.8
gunicorn==20.0.4
importlib-metadata==1.7.0
iniconfig==1.0.1
isort==4.3.21
itsdangerous==1.1.0
Jinja2==2.11.2
lazy-object-proxy==1.4.3
MarkupSafe==1.1.1
mccabe==0.6.1
more-itertools==8.5.0
packaging==20.4
pkg-resources==0.0.0
pluggy==0.13.1
py==1.9.0
pylint==2.5.3
pyparsing==2.4.7
pytest==6.0.1
python-dateutil==2.8.1
pytz==2020.1
six==1.15.0
toml==0.10.1
typed-ast==1.4.1
Werkzeug==1.0.1
wrapt==1.12.1
zipp==3.1.0