Skip to content

Instantly share code, notes, and snippets.

@camsom
Created November 18, 2014 19:32
Show Gist options
  • Save camsom/88d15631002619781570 to your computer and use it in GitHub Desktop.
Save camsom/88d15631002619781570 to your computer and use it in GitHub Desktop.
class Post(object):
def __init__(self, *args, **kwargs):
self.created_time = kwargs.pop("created_time")
self.author = kwargs.pop("from")["name"]
self.message = kwargs.pop("message", "")
self.link_url = kwargs.pop("link", "")
self.picture_url = kwargs.pop("picture", "")
self.description = kwargs.pop("description", "")
self.is_comment = kwargs.pop("is_comment", False)
if "comments" in kwargs:
self.comments = self.get_comments(kwargs.pop("comments")["data"])
super(Post, self).__init__()
@property
def created_on(self):
created = self.created_time.partition("+")[0]
dt = datetime.strptime(created, "%Y-%m-%dT%H:%M:%S")
return dt
@property
def latest_comment(self):
if not self.comments:
return None
return max(self.comments, key=lambda x: x.created_on)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment