track which posts are reblogs

This commit is contained in:
codl 2017-12-27 21:23:13 +01:00
parent b72fbac24d
commit 3c6a9e4158
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
5 changed files with 28 additions and 4 deletions

View File

@ -156,6 +156,7 @@ def post_from_api_object(obj, instance):
direct=obj['visibility'] == 'direct', direct=obj['visibility'] == 'direct',
favourites=obj['favourites_count'], favourites=obj['favourites_count'],
reblogs=obj['reblogs_count'], reblogs=obj['reblogs_count'],
is_reblog=obj['reblog'] is not None,
) )

View File

@ -119,6 +119,7 @@ def post_from_api_tweet_object(tweet, post=None):
post.favourites = tweet['favorite_count'] post.favourites = tweet['favorite_count']
if 'retweet_count' in tweet: if 'retweet_count' in tweet:
post.reblogs = tweet['retweet_count'] post.reblogs = tweet['retweet_count']
post.is_reblog = 'retweeted_status' in tweet
return post return post

View File

@ -0,0 +1,24 @@
"""add is_reblog to Post
Revision ID: 7e255d4ea34d
Revises: 83510ef8c1a5
Create Date: 2017-12-27 21:18:48.988601
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7e255d4ea34d'
down_revision = '83510ef8c1a5'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('posts', sa.Column('is_reblog', sa.Boolean(), server_default='FALSE', nullable=False))
def downgrade():
op.drop_column('posts', 'is_reblog')

View File

@ -17,14 +17,10 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('posts', sa.Column('favourites', sa.Integer(), nullable=True)) op.add_column('posts', sa.Column('favourites', sa.Integer(), nullable=True))
op.add_column('posts', sa.Column('reblogs', sa.Integer(), nullable=True)) op.add_column('posts', sa.Column('reblogs', sa.Integer(), nullable=True))
# ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('posts', 'reblogs') op.drop_column('posts', 'reblogs')
op.drop_column('posts', 'favourites') op.drop_column('posts', 'favourites')
# ### end Alembic commands ###

View File

@ -249,6 +249,8 @@ class Post(db.Model, TimestampMixin, RemoteIDMixin):
favourites = db.Column(db.Integer) favourites = db.Column(db.Integer)
reblogs = db.Column(db.Integer) reblogs = db.Column(db.Integer)
is_reblog = db.Column(db.Boolean, server_default='FALSE', nullable=False)
def __str__(self): def __str__(self):
return '<Post ({}, Author: {})>'.format(self.id, self.author_id) return '<Post ({}, Author: {})>'.format(self.id, self.author_id)