Skip to content

Commit

Permalink
Auto populate Item.json_data
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Jun 21, 2021
1 parent a171acc commit c4e8532
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions src/webqueue2api/parser/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,51 @@ def __init__(self, queue: str, number: int) -> None:
self.department = self.__get_most_recent_header_by_type("Department")
self.building = self.__get_most_recent_header_by_type("Building")
self.date_received = self.__get_formatted_date(self.__get_most_recent_header_by_type("Date"))
self.json_data = self.__generate_json_data()

# TODO: Autopopulate jsonData w/ __dir__() command. Exclude `^_` and `jsonData`.
self.json_data = {
"queue": self.queue,
"number": self.number,
"lastUpdated": self.last_updated,
"headers": self.headers,
"content": self.content,
"isLocked": self.is_locked,
"userEmail": self.user_email,
"userName": self.user_name,
"userAlias": self.user_alias,
"assignedTo": self.assigned_to,
"subject": self.subject,
"status": self.status,
"priority": self.priority,
"department": self.department,
"building": self.building,
"dateReceived": self.date_received
}
def __generate_json_data(self) -> dict:
"""Generates a JSON serializable data dictionary of class attributes.
Example:
__generate_json_data() returns:
{
"assigned_to": 'bekuma',
"building": '',
"content": [...],
"date_received": '2020-08-20T22: 06: 08+0000',
"departmen"': '',
"headers": [...],
"is_locked"': False,
"last_updated": '2021-06-04T11: 01: 00-0400',
"number": 1,
"path": '/home/pier/e/queue/Mail/ce/1',
"priority": '',
"queue": 'ce',
"status": 'archiving from zsite',
"subject": 'RE: Updating my computer',
"user_alias": 'govind',
"user_email": 'govind@purdue.edu',
"user_name": 'Govindaraju, Rao S'
}
Returns:
dict: JSON serializable data dictionary of class attributes.
"""
json_data = {}

# List of attributes that need processing before being added to json_data
attributes_to_process = ["path"]
for attribute in attributes_to_process:
if attribute == "path":
json_data[attribute] = str(self.path)

# List of attributes to be ignored
attributes_to_ignore = ["to_json", "json_data"] + attributes_to_process
for attribute in self.__dir__():
if not attribute.startswith("_") and attribute not in attributes_to_ignore:
json_data[attribute] = self.__getattribute__(attribute)

return json_data

def __get_time_last_updated(self) -> str:
"""Returns last modified time of item reported by the filesystem in mm-dd-yy hh:mm am/pm format.
Expand Down

0 comments on commit c4e8532

Please sign in to comment.