Skip to content

Instantly share code, notes, and snippets.

@Bachmann1234
Last active August 29, 2015 14:23
Show Gist options
  • Save Bachmann1234/c85252bc67e1ae844adb to your computer and use it in GitHub Desktop.
Save Bachmann1234/c85252bc67e1ae844adb to your computer and use it in GitHub Desktop.
Historical Events
import json
from dateutil import parser
class HistoricalEvent(object):
def __init__(self, event_id, name, description, event_time):
"""
:type id: int
:type name: str
:type description: str
:type event_time: datetime.datetime
"""
self.event_id = event_id
self.description = description
self.name = name
self.event_time = event_time
def __eq__(self, other):
return self.__dict__ == other.__dict__
def __repr__(self):
return str(self.__dict__)
@staticmethod
def fromJson(dct):
"""
:type data: dict
Data hopefully representing a User
:return: User
"""
return HistoricalEvent(
dct['event_id'],
dct['name'],
dct['description'],
parser.parse(dct['event_time'])
)
class EventEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, HistoricalEvent):
return {
"event_id": obj.event_id,
"name": obj.name,
"description": obj.description,
"event_time": obj.event_time.isoformat(),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment