示例#1
0
def get_article_edit_json():
    '''获取文章内容'''
    args = request.form

    id = args.get('id', None)

    if id:
        Article.update_article_by_id(**args)

    return return_model()
示例#2
0
    def delete_resource(cls, res_id, res_type):
        res = None
        if res_type == BaseConfig.TYPE_VIDEO_PLAY:
            res = Video.update_video_by_id(
                id=res_id,
                is_del=1
            )
        elif res_type == BaseConfig.TYPE_ARTICLE:
            res = Article.update_article_by_id(
                id=res_id,
                is_del=1
            )
        elif res_type == BaseConfig.TYPE_IMAGE:
            res = Image.update_image_by_id(
                id=res_id,
                is_del=1
            )
        elif res_type == BaseConfig.TYPE_AUDIO:
            res = Audio.update_audio_by_id(
                id=res_id,
                is_del=1
            )
        elif res_type == BaseConfig.TYPE_PUSH:
            res = Push.update_push_by_id(
                id=res_id,
                is_del=1
            )
        elif res_type == BaseConfig.TYPE_COLLECTION:
            res = Collection.update_by_id(
                id=res_id,
                is_del=1
            )

        return res
示例#3
0
    def get_resource_list(cls, res_type):
        res = []
        if res_type == BaseConfig.TYPE_VIDEO_PLAY:
            res = Video.get_videos()
        elif res_type == BaseConfig.TYPE_ARTICLE:
            res = Article.get_articles()

        return res
示例#4
0
def get_articles(**params):
    arts = Article.query_articles(**params)
    print(arts)

    items = []
    for item in arts:
        items.append(item.to_json())

    return items
示例#5
0
def create_article():
    '''创建文章'''
    print(request.form)
    print(request.content_type)
    args = request.form
    key = check_params(args, 'name', 'content')
    if key:
        return http_util.return_param_not_found(key)

    a = Article.create_article(**args)

    return return_model(data={"article_id": a.id})
示例#6
0
def get_article(article_id):
    '''获取文章内容'''
    a = Article.query_article(id=article_id)

    item = a.to_json()

    item['article_id'] = item['id']
    item['create_ts'] = utils.make_timestamp_for_sql_time(item['create_ts'])

    del item['id']
    del item['is_del']
    del item['update_ts']
    return return_model(data=item)
示例#7
0
def get_article_list_json():
    '''获取文章内容'''
    args = request.args
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    paginate = Article.query_article_paginate(page=page, per_page=per_page)
    details = []
    for item in paginate.items:
        detail = item.to_json()
        del detail['content']
        details.append(detail)

    res = http_util.make_page_response(details, paginate.total, page, per_page)

    return return_model(data=res)
示例#8
0
def sync_index_by_type(type):
    """根据type刷新索引"""
    args = make_search_args(type)
    items = []
    if type == BaseConfig.TYPE_USER:
        items = User.get_normal_users()
    elif type == BaseConfig.TYPE_VIDEO_PLAY:
        items = Video.get_videos()
    elif type == BaseConfig.TYPE_ARTICLE:
        items = Article.get_articles()
    elif type == BaseConfig.TYPE_AUDIO:
        items = Audio.get_items()
    elif type == BaseConfig.TYPE_COLLECTION:
        items = Collection.get_items()
    else:
        return False

    es.delete_index_by_type(**args)
    for item in items:
        args['id'] = item['res_id']
        item = format_item(item)
        args['body'] = item
        es.sync_index(**args)
示例#9
0
    def change_online_status(cls, res_id, res_type, is_online):
        res = None
        if res_type == BaseConfig.TYPE_VIDEO_PLAY:
            res = Video.update_video_by_id(
                id=res_id,
                is_online=is_online
            )
        elif res_type == BaseConfig.TYPE_ARTICLE:
            res = Article.update_article_by_id(
                id=res_id,
                is_online=is_online
            )
        elif res_type == BaseConfig.TYPE_IMAGE:
            res = Image.update_image_by_id(
                id=res_id,
                is_online=is_online
            )
        elif res_type == BaseConfig.TYPE_AUDIO:
            res = Audio.update_audio_by_id(
                id=res_id,
                is_online=is_online
            )

        return res
示例#10
0
    def get_resource_detail(cls, res_id, res_type, source_include=[], **params):
        """获取资源详情"""
        detail = None
        login_user_id = g.user_id
        if res_type == BaseConfig.TYPE_VIDEO_PLAY:
            detail = Video.get_video_detail(res_id)
        elif res_type == BaseConfig.TYPE_ARTICLE:
            detail = Article.get_article_detail(res_id)
            if not detail:
                app.logger.error('{} not found'.format(res_id))
                return None
            del detail['content']
        elif res_type == BaseConfig.TYPE_AUDIO:
            detail = Audio.get_audio_detail(res_id)
        elif res_type == BaseConfig.TYPE_IMAGE:
            detail = Image.get_image_detail(res_id)
        elif res_type == BaseConfig.TYPE_COLLECTION:
            detail = Collection.get_collection_detail(res_id)
            subs = []
            if 'items' in source_include:
                items = CollectionResource.query_items(collection_id=res_id)
                for item in items:
                    sub_id = item.res_id
                    sub_type = item.res_type

                    sub_detail = Resource.get_resource_detail(
                        res_id=sub_id,
                        res_type=sub_type,
                        source_include=['comment_count', 'view_count',
                                        'like_count'],
                        login_user_id=login_user_id
                    )
                    if sub_detail:
                        subs.append(sub_detail)
            detail['items'] = subs

        if not detail:
            return None

        # 添加评论
        if 'comments' in source_include:
            comments = get_comments(
                res_id=res_id,
                start=BaseConfig.MAX_START,
                per_page=5
            )
            detail['comments'] = comments

        # 相关视频
        if 'related_items' in source_include and res_type != BaseConfig.TYPE_COLLECTION:
            related_videos = Video.query_related_videos(res_id)
            detail['related_items'] = related_videos

        ext = detail.get('ext', {})
        # 观看数量
        if 'view_count' in source_include:
            count = Action.query_count(
                type=BaseConfig.TYPE_ACTION_VIEW,
                res_id=res_id
            )
            ext['view_count'] = count

        # 点赞数量
        if 'like_count' in source_include:
            count = LikeInfo.query_count(
                res_id=res_id,
                res_type=res_type
            )
            ext['like_count'] = count

        # 评论数量
        if 'comment_count' in source_include:
            count = Comment.query_count(
                res_id=res_id,
                res_type=res_type
            )
            ext['comment_count'] = count

        detail['ext'] = ext

        # 关注状态
        detail['is_like'] = 0
        if login_user_id:
            is_like = LikeInfo.query_like(
                user_id=login_user_id,
                res_id=res_id,
                res_type=res_type
            )
            if is_like:
                detail['is_like'] = 1
        return detail
示例#11
0
from src.api.location.models import create_location
from src.api.location.models import query_user_last_location
from src.api.home_page.models import ViewHotRes
from src import db
from sqlalchemy import text
from src.common.pymysql_util import execute
from src.common import utils

from src.api.code.models import Code
from src.api.collection.models import CollectionResource
from tests.test_snowflake import Snowflake
from src.common.aliyun_util import put_object

if __name__ == '__main__':

    items = Article.query_articles(is_del=0)
    for item in items:
        poster = item.poster
        print(poster)
        try:
            res = requests.get(poster)
            print(res)
            if res.status_code == 200:
                suffix = poster.rsplit('.', 1)[1]
                datetime_root = time.strftime("%Y%m%d/%H/%M%S",
                                              time.localtime())
                url = put_object(key='{}/{}.{}'.format(datetime_root,
                                                       int(time.time()),
                                                       suffix),
                                 data=res.content,
                                 bucket_name=BaseConfig.ALIYUN_BUCKET_IMG)