Example #1
0
class Base(db.Model):
    __abstract__ = True

    id = db.Column('id', db.Integer, primary_key=True)
    created_at = db.Column('created_at', db.DateTime(timezone=True), default=db.func.current_timestamp())
    updated_at = db.Column('updated_at', db.DateTime(timezone=True),default=db.func.current_timestamp(),
                           onupdate=db.func.current_timestamp())

    def create(self):
        db.session.add(self)
        db.session.commit()
        db.session.flush()

    def update(self):
        db.session.commit()
        db.session.flush()

    def bulk_insert(self, data):
        db.session.bulk_insert_mappings(self, data)
        db.session.commit()
        db.session.flush()

    def last_updated_id(self, class_name):
        return db.session.query(class_name).order_by(class_name.id.desc()).first()

    def save(self):
        db.session.add(self)
        db.session.commit()
        return self

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Example #2
0
class Hash(Base):
    id = db.Column(db.Integer, primary_key=True, index=True)
    hashtag = db.Column(db.String(50), index=True, unique=True)

    def __init__(self, hashtag):
        self.hashtag = hashtag

    def __repr__(self):
        return '<%s %s>' % (self.id, self.hashtag)
Example #3
0
class Like(Base):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.String(40),
                        db.ForeignKey('post.post_id'),
                        index=True)
    user_id = db.Column(db.String(40), index=True)
    user_name = db.Column(db.String(200))

    def __init__(self, post_id, user_id, user_name):
        self.post_id = post_id
        self.user_id = user_id
        self.user_name = user_name

    def __repr__(self):
        return '<%s %s %s>' % (self.post_id, self.user_id, self.user_name)
Example #4
0
class Photo(Base):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.String(40),
                        db.ForeignKey('post.post_id'),
                        index=True)
    photo_desc = db.Column(db.Text)
    photo = db.Column(db.String(900), index=True)

    def __init__(self, post_id, photo_desc, photo):
        self.post_id = post_id
        self.photo_Desc = photo_desc
        self.photo = photo

    def __repr__(self):
        return '<%s %s %s>' % (self.post_id, self.photo_desc, self.photo)
Example #5
0
class PostInsight(Base):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.String(40),
                        db.ForeignKey('post.post_id'),
                        index=True)
    post_impressions = db.Column(db.Integer, index=True)
    post_consumptions = db.Column(db.Integer, index=True)
    post_impressions_unique = db.Column(db.Integer, index=True)

    def __init__(self, post_id, post_impressions, post_consumptions,
                 post_impressions_unique):
        self.post_id = post_id
        self.post_impressions = post_impressions
        self.post_consumptions = post_consumptions
        self.post_impressions_unique = post_impressions_unique

    def __repr__(self):
        return '<%s %s %s %s>' % (self.post_id, self.post_impressions,
                                  self.post_consumptions,
                                  self.post_impressions_unique)
Example #6
0
class Comment(Base):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.String(40),
                        db.ForeignKey('post.post_id'),
                        index=True)
    user_id = db.Column(db.String(40), index=True)
    user_name = db.Column(db.String(800))
    user_message = db.Column(db.Text)

    def __init__(self, post_id, user_id, user_name, user_message,
                 user_created_time):
        self.post_id = post_id
        self.user_id = user_id
        self.user_name = user_name
        self.user_message = user_message
        self.user_created_time = user_created_time

    def __repr__(self):
        return '<%s %s %s %s %s>' % (self.post_id, self.user_id,
                                     self.user_name, self.user_message,
                                     self.user_created_time)
Example #7
0
class User(Base):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String(40), index=True)
    user_name = db.Column(db.String(40))
    user_screen_name = db.Column(db.String(40))
    user_description = db.Column(db.Text)
    user_photo = db.Column(db.Text)
    page_id = db.Column(db.String(50),
                        db.ForeignKey('channel.page_id'),
                        index=True)

    def __init__(self, user_id, user_name, user_screen_name, user_description,
                 user_photo, page_id):
        self.user_id = user_id
        self.user_name = user_name
        self.user_screen_name = user_screen_name
        self.user_description = user_description
        self.user_photo = user_photo
        self.page_id = page_id

    def __repr__(self):
        return '<%s %s %s %s %s %s>' % (
            self.user_id, self.user_name, self.user_screen_name,
            self.user_description, self.user_photo, self.page_id)
Example #8
0
class Channel(Base):
    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.Integer, index=True)
    page_id = db.Column(db.String(40), index=True, unique=True)
    page_name = db.Column(db.String(50), index=True)
    followers = db.Column(db.Integer)
    following = db.Column(db.Integer)
    description = db.Column(db.Text)
    website = db.Column(db.String(50))
    phone = db.Column(db.String(30))
    admin = db.Column(db.Boolean, default=False)
    influencer = db.Column(db.Boolean, default=False, index=True)

    def __init__(self, type, page_id, page_name, followers, following,
                 description, website, phone, admin, influencer):
        self.type = type
        self.page_id = page_id
        self.page_name = page_name
        self.followers = followers
        self.following = following
        self.description = description
        self.website = website
        self.phone = phone
        self.admin = admin
        self.influencer = influencer

    def __repr__(self):
        return '<%s %s %s %s %s %s %s %s %s %s %s>' % (
            self.id, self.type, self.page_id, self.page_name, self.followers,
            self.following, self.description, self.website, self.phone,
            self.admin, self.influencer)
Example #9
0
# -*- coding: utf-8 -*-
from tdg_social import db
from tdg_social.models.base import Base


class Hash(Base):
    id = db.Column(db.Integer, primary_key=True, index=True)
    hashtag = db.Column(db.String(50), index=True, unique=True)

    def __init__(self, hashtag):
        self.hashtag = hashtag

    def __repr__(self):
        return '<%s %s>' % (self.id, self.hashtag)


association_tags = db.Table(
    'tags', Base.metadata,
    db.Column('tag_id', db.Integer, db.ForeignKey('hash.id')),
    db.Column('post_id', db.Integer, db.ForeignKey('post.id')))
Example #10
0
class Post(Base):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.String(40), unique=True)
    post_type = db.Column(db.String(10), index=True)
    post_created_time = db.Column(db.DateTime(timezone=True), index=True)
    post_content = db.Column(db.Text)
    post_link = db.Column(db.String(700))
    post_likes = db.Column(db.Integer, index=True)
    post_comments = db.Column(db.Integer, index=True)
    post_shares = db.Column(db.Integer, index=True)
    post_photos = db.Column(db.ARRAY(db.String(500)))
    page_id = db.Column(db.Integer, db.ForeignKey('channel.id'), index=True)
    hashtags = db.relationship('Hash',
                               secondary=association_tags,
                               backref=db.backref('posts', lazy='dynamic'))

    def __init__(self, post_id, post_type, post_created_time, post_content,
                 post_link, post_likes, post_comments, post_shares,
                 post_photos, page_id):
        self.post_id = post_id
        self.post_type = post_type
        self.post_created_time = post_created_time
        self.post_content = post_content
        self.post_link = post_link
        self.post_likes = post_likes
        self.post_comments = post_comments
        self.post_shares = post_shares
        self.post_photos = post_photos
        self.page_id = page_id

    @hybrid_property
    def get_hash(self):
        hashtag_list = list({
            i.strip("#")
            for i in self.__getattribute__('post_content').split()
            if i.startswith("#")
        })
        return hashtag_list

    def __repr__(self):
        return '<%s %s %s %s %s %s %s %s %s %s >' % (
            self.post_id, self.post_type, self.post_created_time,
            self.post_content, self.post_link, self.post_likes,
            self.post_comments, self.post_shares, self.post_photos,
            self.page_id)