Пример #1
0
class Bucket(db.Model):
    __tablename__ = "bucket"

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    user_id = db.Column(db.BigInteger, db.ForeignKey('user.id'), index=True)
    user = db.relationship("User", )
    name = db.Column(db.Text, nullable=False)
    slug = db.Column(db.Text, nullable=False, index=True)
    created_at = db.Column(db.DateTime)
    follower_count = db.Column(db.Integer)
    projects = db.Column(postgresql.ARRAY(db.String))

    def jsonable(self):
        return {
            'id': unicode(self.id),
            'name': unicode(self.name),
            'slug': unicode(self.slug),
            'created_at': unicode(format_date(self.created_at)),
            'projects': unicode(self.projects),
            'follower_count': unicode(self.follower_count)
        }

    def __repr__(self):
        return str(self.jsonable())

    def __str__(self):
        return str(self.name)
Пример #2
0
def find_existing_posts(feed_id, post_id_hashes, post_link_hashes):
    try:

        return session.query(Post.post_id_hash, Post.link_hash).filter(
            and_(
                Post.feed_id == feed_id,
                or_(
                    Post.post_id_hash.in_(post_id_hashes),
                    Post.link_hash.in_(post_link_hashes),
                )))
    except:
        session.rollback()
        error_reporter.captureException()
        return None
Пример #3
0
def rss_exists(url):
    rss_hash = url_hash(url)
    feed = None

    try:
        feed = session.query(Feed).filter_by(rss_hash=rss_hash).first()
    except:
        error_reporter.captureException()
        try:
            session.rollback()
        except:
            error_reporter.captureException()
        raise

    return feed
Пример #4
0
class Package(db.Model):
    __tablename__ = 'package'

    name = db.Column('name', db.Text, nullable=False,index=True,primary_key=True)
    author = db.Column('author', db.Text, nullable=False)
    author_email = db.Column('author_email', db.Text, nullable=False)
    summary = db.Column('summary', db.Text, nullable=False)
    description = db.Column('description', db.Text, nullable=False)
    url = db.Column('url', db.Text, nullable=False)
    mdown = db.Column('mdown', db.Integer, nullable=False)
    wdown = db.Column('wdown', db.Integer, nullable=False)
    ddown = db.Column('ddown', db.Integer, nullable=False)
    data = db.Column('data', db.Text, nullable=False)

    @property
    def download(self):
        return nice_number(self.mdown)
Пример #5
0
class Action(db.Model):
    __tablename__ = "action"

    id = db.Column(db.BigInteger, primary_key=True)
    from_id = db.Column(db.BigInteger, nullable=False)
    to_id = db.Column(db.BigInteger)
    action = db.Column(db.SmallInteger, nullable=False)
    created_at = db.Column(db.DateTime,default=dt.utcnow())
    deleted_at = db.Column(db.DateTime)
    deleted = db.Column(db.Boolean, default=False)

    def jsonable(self):
        return {
            'id': unicode(self.id),
            'from_id': unicode(self.from_id),
            'to_id': unicode(self.to_id),
            'action': unicode(self.action),
            'created_at': unicode(format_date(self.created_at)),
            'deleted_at': unicode(format_date(self.deleted_at)),
            'deleted': unicode(self.deleted),
        }

    def __str__(self):
        return str(self.jsonable())

    def __repr__(self):
        return str(self.jsonable())
Пример #6
0
class SocialUser(db.Model):
    __tablename__ = 'social_user'

    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(100), nullable=True)
    email = Column(String(120), index=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relation(User)
    nick = Column(String(64), index=True)
    acc_type = Column(String(2), nullable=False)
    follower_count = Column(Integer, nullable=True)
    following_count = Column(Integer, nullable=True)
    ext_id = Column(String(50))
    access_token = Column(String(100))
    hireable = Column(Boolean)

    def __repr__(self):
        return '<SocialUser %s-%s->' % (self.acc_type, self.user_id)
Пример #7
0
class Channel(db.Model):
    __tablename__ = "channel"

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    name = db.Column(db.Text, nullable=False)
    slug = db.Column(db.Text, nullable=False, index=True, unique=True)
    created_at = db.Column(db.DateTime)

    post_count = db.Column(db.BigInteger)

    disabled = db.Column(db.Boolean)

    def jsonable(self):
        return {
            'id': unicode(self.id),
            'name': unicode(self.name),
            'slug': unicode(self.slug),
            'post_count': unicode(self.post_count),
            'disabled': unicode(self.disabled),
            'created_at': unicode(format_date(self.created_at)),
        }

    def __repr__(self):
        return str(self.jsonable())

    def __str__(self):
        return str(self.name)
Пример #8
0
def get_feed(rss_url, stats=False):
    post_ids = []

    try:
        for o in download_feed_return_objects(rss_url):
            if o is None:
                continue
            if isinstance(o, Post):
                post_ids.append(o.id)
            session.add(o)
        try:
            if len(post_ids):
                session.commit()
        except Exception, ex:
            session.rollback()
            error_reporter.captureException()
            logging.exception(ex)
            return False

        if len(post_ids) > 0:
            logging.info(u"Saved %d posts for %s" %
                         (len(post_ids), safe_str(rss_url)))
        else:
            logging.info(u"No Posts saved for %s" % safe_str(rss_url))

        for id in post_ids:
            if stats:
                task('get_post_stats', args=(str(id), )).apply_async()
            task('index_post', args=(str(id), )).apply_async()
Пример #9
0
class Tutorial(db.Model):
    __tablename__ = "tutorial"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    user_id = db.Column(db.BigInteger, db.ForeignKey('user.id'), index=True)
    user = db.relationship("User", )

    title = db.Column(db.Text, nullable=False)
    slug = db.Column(db.Text, nullable=False, index=True)

    keywords = db.Column(db.Text, nullable=False)
    meta_description = db.Column(db.Text, nullable=False)

    content = db.Column(db.Text, nullable=False)
    content_html = db.Column(db.Text, nullable=False)

    created_at = db.Column(db.DateTime)
    generated_at = db.Column(db.DateTime)

    publish = db.Column(db.Boolean, default=True)
    spam = db.Column(db.Boolean, default=False)

    upvote_count = db.Column(db.Integer, default=1)

    @staticmethod
    def to_dict(obj):
        assert isinstance(obj, Tutorial)

        return {
            'id': unicode(obj.id),
            'title': unicode(obj.name),
            'slug': unicode(obj.slug),
            'created_at': unicode(format_date(obj.created_at)),
            'generated_at': unicode(format_date(obj.generated_at)),
            'keywords': unicode(obj.keywords),
            'content': unicode(obj.content),
            'content_html': unicode(obj.content_html),
            'meta_description': unicode(obj.meta_description),
            'upvote_count': obj.upvote_count or 0,
            'spam': obj.spam
        }

    def __repr__(self):
        return str(Tutorial.to_dict(self))

    def __str__(self):
        return str(self.name)
Пример #10
0
class Message(db.Model):
    __tablename__ = "message"

    id = db.Column(BigInteger, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship(User)
    user_nick = db.Column(db.String)
    reply_to_id = db.Column(db.String)
    reply_to_uid = db.Column(db.String)
    reply_to_uname = db.Column(db.String)

    ext_id = db.Column(String)
    ext_reply_id = db.Column(String())

    slug = db.Column(Text)
    content = db.Column(Text)
    content_html = db.Column(Text)
    lang = db.Column(String(length=3))

    mentions = db.Column(postgresql.ARRAY(String))
    urls = db.Column(postgresql.ARRAY(String))
    tags = db.Column(postgresql.ARRAY(String))
    media = db.Column(postgresql.ARRAY(String))

    has_url = db.Column(db.Boolean)
    has_channel = db.Column(db.Boolean)

    karma = db.Column(db.Float)
    up_votes = db.Column(db.Integer)
    down_votes = db.Column(db.Integer)
    favorites = db.Column(db.Integer)

    published_at = db.Column(db.DateTime, default=dt.utcnow())

    channel_id = db.Column(
        db.Integer,
        db.ForeignKey('channel.id'),
        index=True,
    )
    channel = db.relationship(Channel)
    channels = db.Column(postgresql.ARRAY(String))

    spam = db.Column(db.Boolean, default=False)
    flagged = db.Column(db.Boolean, default=False)

    deleted = db.Column(db.Boolean, default=False)

    def jsonable(self, date_converter=format_date):
        return {
            'id': str(self.id),
            'user_id': str(self.user_id),
            'reply_to_id': str(self.reply_to_id),
            'content': self.content,
            'content_html': self.content_html,
            'lang': self.lang,
            'published_at': date_converter(self.published_at),
            'media': self.media,
            'channels': self.channels,
            'mentions': self.mentions,
            "urls": self.urls,
            "tags": self.tags,
        }

    def __str__(self):
        return str(self.jsonable())
Пример #11
0
class OpenSourceProject(db.Model):
    id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
    name = db.Column('name', db.String(100), nullable=False)
    slug = db.Column('slug', db.String(100), unique=True, index=True, nullable=False)
    description = db.Column('description', db.Unicode(500))
    src_url = db.Column('src_url', db.Unicode(200))
    doc_url = db.Column('doc_url', db.Unicode(200))
    stars = db.Column('starts', db.Integer)
    watchers = db.Column('watchers', db.Integer)
    forks = db.Column('forks', db.Integer)
    parent = db.Column("parent", db.String(100), nullable=True, index=True )
    categories = db.Column("categories", postgresql.ARRAY(db.String))

    hide = db.Column("hide", db.Boolean, default=False)
    lang = db.Column("lang", db.SmallInteger, default=0)
    __tablename__ = 'os_project'


    def jsonable(self, **kwargs):
        result = {
            'id' : unicode(self.id),
            'slug' : unicode(self.slug),
            'name' : unicode(self.name),
            'src_url' : unicode(self.src_url),
            'description' : unicode(self.description),
            'watchers': self.watchers
        }

        result.update(**kwargs)
        return result