class User(MBase): id = columns.Integer(primary_key=True) nick = columns.Text(required=True, index=True) extended = columns.Map(columns.Text, columns.Text) registered_at = columns.BigInt(default=unix_time(dt.utcnow())) created_at = columns.BigInt(default=unix_time(dt.utcnow())) def to_dict(self): return { 'id': self.id, 'nick': self.nick, 'properties': self.extended, }
class ProjectFollower(MBase): """ A user following a project """ project_id = columns.Integer(primary_key=True) user_id = columns.Integer(primary_key=True) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class UserFollowing(MBase): """ A user follows another user """ user_id = columns.Integer(primary_key=True) following_id = columns.Integer(primary_key=True) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class UserFollower(MBase): """ Followers of a user """ user_id = columns.Integer(primary_key=True) follower_id = columns.Integer(primary_key=True) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class DiscussionFollower(MBase): """ Users who follows a discussion """ disc_id = columns.BigInt(primary_key=True) user_id = columns.Integer(primary_key=True) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class Discussion(MBase): id = columns.BigInt(primary_key=True) title = columns.Text(required=True) slug = columns.Text(required=True, index=True) user_id = columns.Integer(index=True) users = columns.Set(value_type=columns.Integer) post_id = columns.BigInt() last_message = columns.BigInt() published_at = columns.BigInt(default=unix_time(dt.utcnow())) topic_id = columns.Integer(required=False, index=True) def to_dict(self): return { 'id': unicode(self.id), 'title': self.title, 'slug': self.slug, 'user_id': self.user_id, 'post_id': unicode(self.post_id), 'last_message': unicode(self.last_message), 'published_at': epoch_to_date(self.published_at), 'topic_id': unicode(self.topic_id) if self.topic_id is not None else None, } @property def published_date(self): return epoch_to_date(self.published_at*1000) @property def published_date_str(self): d = epoch_to_date(self.published_at*1000) return d.strftime("%y%m%d %H%M%S")
def _create_event(json_resp): for event in json_resp: event_id = int(event.get("id", None)) event_type = event.get("type", "").replace("Event", "") actor = event.get("actor", None) actor_str = "{},{}".format(actor.get("id", ""), actor.get("login")) repo = event.get("repo", None) repo_str = None if repo is not None: repo_str = "{},{}".format(repo.get("id", ""), repo.get("name")) public = event.get("public", None) created_at = unix_time(dt_parser.parse( event.get("created_at", dt.utcnow())).replace(tzinfo=None), float=False) org = event.get("org", None) org_str = None if org is not None: org_str = "{},{}".format(org.get("id", ""), org.get("login")) payload = event.get("payload", {}) GithubEvent.create(id=event_id, type=event_type, actor=actor_str, org=org_str, repo=repo_str, created_at=created_at, payload=simplejson.dumps(payload))
class PostVote(MBase): """ All upvotes/downvotes sent to a post """ post_id = columns.BigInt(primary_key=True, partition_key=True) user_id = columns.Integer(primary_key=True) positive = columns.Boolean(default=True) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class Story(MBase): """ A story is an event happened in the network. User A followed User B User A starred a project. User A posted a message. User A started a discussion User A mentioned User B in a post(message) - What to do for multiple mentions ? """ id = columns.BigInt(primary_key=True) actor = columns.Integer(partition_key=True) type = columns.Integer(required=True) target = columns.BigInt() payload = columns.Map(columns.Ascii, columns.Ascii) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class Topic(MBase): id = columns.Integer(primary_key=True) slug = columns.Text() name = columns.Text() description = columns.Text() last_message_id = columns.BigInt(required=False) last_message_time = columns.BigInt(default=unix_time(dt.utcnow())) main_topic = columns.Boolean(default=False) parent_topic = columns.Integer(required=False) subtopics = columns.Set(value_type=columns.Integer) def to_dict(self): return { 'slug': self.slug, 'name': self.name }
class ChannelFollower(MBase): channel_id = columns.Integer(primary_key=True) user_id = columns.Integer(primary_key=True) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class PostFollower(MBase): post_id = columns.TimeUUID(primary_key=True) user_id = columns.Integer(primary_key=True) created_at = columns.BigInt(default=unix_time(dt.utcnow()))
class Post(MBase): id = columns.BigInt(index=True, primary_key=True) user_id = columns.Integer(required=True, index=True, partition_key=True) user_nick = columns.Text() text = columns.Text(required=True) html = columns.Text(required=False) reply_to_id = columns.BigInt() reply_to_uid = columns.Integer() reply_to_nick = columns.Text() ext_id = columns.Text() has_url = columns.Boolean() has_channel = columns.Boolean() # this post is either linked to a DISCUSSION or discussion_id = columns.BigInt() # CHANNEL or None channel_id = columns.Integer() spam = columns.Boolean(default=False) flagged = columns.Boolean(default=False) deleted = columns.Boolean(default=False) stats = columns.Map(columns.Ascii, columns.Integer) created_at = columns.BigInt(default=unix_time(dt.utcnow())) def to_dict(self): return {'id': unicode(self.id), 'text': self.text, 'html': self.html, 'user_id': self.user_id, 'reply_to_id': self.reply_to_id, 'reply_to_uid': self.reply_to_uid, 'reply_to_nick': self.reply_to_nick, 'discussion_id': unicode(self.discussion_id) if self.discussion_id is not None else "", 'discussion_name': unicode(self.discussion_name) if hasattr(self,"discussion_name") else "", 'discussion_slug': unicode(self.discussion_slug) if hasattr(self,"discussion_slug") else "", 'channel_id': self.channel_id, 'spam': self.spam, 'flagged': self.flagged, 'deleted': self.deleted, 'published_at': self.created_at, 'ago': self.ago, 'user': {'id': self.user_id, 'nick': self.user_nick}, 'stats': self.__dict__.get('statistics', {}), 'upvoted': self.__dict__.get('upvoted', False)} @property def ago(self): if self.created_at is None: return "some time ago" result = int(int(int(time.time() - self.created_at)) / 60.0) abb = "m" if result > (60 * 24): result /= (60 * 24) abb = "d" if result > 60: result /= 60 abb = "h" return "{}{} ago".format(result, abb)