Skip to content

Commit

Permalink
Merge pull request #48 from ECN/enhancement-date-parsing-for-header
Browse files Browse the repository at this point in the history
Enhancement date parsing for header
  • Loading branch information
campb303 authored Sep 17, 2020
2 parents 89898bc + 43d4007 commit 286d614
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
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

0 comments on commit 286d614

Please sign in to comment.