当前位置: 首页>>代码示例>>Python>>正文


Python Share.find方法代码示例

本文整理汇总了Python中db.Share.find方法的典型用法代码示例。如果您正苦于以下问题:Python Share.find方法的具体用法?Python Share.find怎么用?Python Share.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在db.Share的用法示例。


在下文中一共展示了Share.find方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
 def get(self):
     action = self.request.path[7:]
     share_res = Share.find()
     if 'add' in action:
         do, share_id, suggestscore = action.split('!')
         share = Share.by_sid(share_id)
         share.suggestscore = float(suggestscore)
         share.save()
     for share in share_res:
         share.score = 0.001 * share.hitnum + share.likenum - \
             share.dislikenum + 0.5 * share.commentnum - \
             share.status + share.suggestscore + 0.5 * share.id
         share.save()
     # self.write_json({'objs': list(Share.find().sort('score',
     # DESCENDING))})
     share_res = Share.find().sort('score', DESCENDING)
     display = ''
     display += '<p>score sugg hit like dis comment status title id</p>'
     for share in share_res:
         display += '<p>%s  %s  %s  %s  %s  %s  %s  %s  %s</p>' % (
             share.score,
             share.suggestscore,
             share.hitnum,
             share.likenum,
             share.dislikenum,
             share.commentnum,
             share.status,
             share.title,
             share.id)
     self.write(display)
开发者ID:randy-ran,项目名称:anwen,代码行数:32,代码来源:other.py

示例2: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
 def get(self, node='home'):
     page = self.get_argument("page", 1)
     # share_res = Share.find({'status': 0}).sort(
     #     'score', DESCENDING).limit(11).skip((int(page) - 1) * 11)
     share_res = Share.find({'status': {'$gte': 1}}).sort(
         '_id', DESCENDING).limit(11).skip((int(page) - 1) * 11)
     pagesum = (share_res.count() + 10) / 11
     shares = []
     for share in share_res:
         if share.id in (48, 47):
             continue
         user = User.by_sid(share.user_id)
         share.name = user.user_name
         share.published = time.strftime(
             '%Y-%m-%d %H:%M:%S', time.localtime(share.published))
         share.domain = user.user_domain
         share.markdown = cutter(
             markdown2.markdown(share.markdown))
         share.title = share.title.split('_')[0]
         shares.append(share)
     self.render(
         "node.html",
         shares=shares,
         pagesum=pagesum, page=page, node=node,
     )
开发者ID:anwen,项目名称:anwen,代码行数:27,代码来源:index.py

示例3: todo_get_suggest

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
def todo_get_suggest(share, current_user):
    posts = Share.find()
    suggest = []
    for post in posts:
        post.score = 100 + post.id - post.user_id + post.commentnum * 3
        post.score += post.likenum * 4 + post.hitnum * 0.01
        post.score += randint(1, 999) * 0.001
        common_tags = [i for i in post.tags.split(
            ' ') if i in share.tags.split(' ')]
        # list(set(b1) & set(b2))
        post.score += len(common_tags)
        if post.sharetype == share.sharetype:
            post.score += 1  # todo
        if current_user:
            is_hitted = Hit.find(
                {'share_id': share.id},
                {'user_id': int(current_user["user_id"])},
            ).count() > 0
        # else:
            # is_hitted = self.get_cookie(share.id)
        if is_hitted:
            post.score -= 50
        suggest.append(post)
    suggest.sort(key=lambda obj: obj.get('score'))
    suggest = suggest[:5]
开发者ID:anwen,项目名称:anwen,代码行数:27,代码来源:api_share.py

示例4: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
    def get(self, node):
        page = self.get_argument("page", 1)
        share_res = Share.find({'sharetype': node}).sort(
            '_id', DESCENDING).limit(10).skip((int(page) - 1) * 10)
        pagesum = (share_res.count() + 9) / 10

        shares = []
        for share in share_res:
            user = User.by_sid(share.user_id)
            share.name = user.user_name
            share.published = time.strftime(
                '%Y-%m-%d %H:%M:%S', time.localtime(share.published))
            share.domain = user.user_domain
            share.markdown = filter_tags(
                markdown2.markdown(share.markdown))[:100]
            share.gravatar = get_avatar(user.user_email, 16)
            shares.append(share)
        members = User.find().sort('_id', DESCENDING).limit(20)
        members_dict = []
        for member in members:
            member.gravatar = get_avatar(member.user_email, 25)
            members_dict.append(member)
        node_about = options.node_about[node]
        self.render(
            "node.html", shares=shares, members=members_dict,
            pagesum=pagesum, page=page, node=node, node_about=node_about)
开发者ID:facesun,项目名称:anwen,代码行数:28,代码来源:index.py

示例5: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
 def get(self):
     user_id = self.current_user['user_id']
     share_id = self.get_argument("delete", None)
     s = self.get_argument("s", None)
     if admin.is_admin(user_id):
         if share_id and not s:
             admin.delete_share(share_id)
         if share_id and s and admin.is_superadmin(user_id):
             admin.delete_share_by_s(share_id)
         if s:
             shares = Share.find({'status': {'$ne': 1}})
             self.render('admin/super_share.html', shares=shares)
         else:
             shares = Share.find()
             self.render('admin/share.html', shares=shares)
     else:
         self.render('admin/join_admin.html')
开发者ID:randy-ran,项目名称:anwen,代码行数:19,代码来源:admin.py

示例6: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
    def get(self):
        share_res = Share.find()
        shares = []
        for share in share_res:
            user = User.by_sid(share.user_id)
            share.name = user.user_name
            share.published = datetime.datetime.fromtimestamp(share.published)
            share.updated = datetime.datetime.fromtimestamp(share.updated)
            share.domain = user.user_domain
            share.content = markdown2.markdown(share.markdown)
            shares.append(share)

        self.set_header("Content-Type", "application/atom+xml")
        self.render("feed.xml", shares=shares)
开发者ID:vivekjishtu,项目名称:anwen,代码行数:16,代码来源:share.py

示例7: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
    def get(self, node):
        page = self.get_argument("page", 1)
        share_res = Share.find({"sharetype": node}).sort("_id", DESCENDING).limit(11).skip((int(page) - 1) * 11)
        pagesum = (share_res.count() + 10) / 11

        shares = []
        for share in share_res:
            user = User.by_sid(share.user_id)
            share.name = user.user_name
            share.published = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(share.published))
            share.domain = user.user_domain
            share.markdown = filter_tags(markdown2.markdown(share.markdown))[:400]
            share.gravatar = get_avatar(user.user_email, 16)
            shares.append(share)

        node_about = options.node_about[node]
        self.render("node.html", shares=shares, pagesum=pagesum, page=page, node=node, node_about=node_about)
开发者ID:bowu8,项目名称:anwen,代码行数:19,代码来源:index.py

示例8: get_share_by_slug

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
def get_share_by_slug(slug):
    # 特殊id ramdom
    if slug == 'random':
        cond = {}
        cond['status'] = {'$gte': 1}
        # shares = Share.find(cond, {'_id': 0})
        shares = Share.find(cond)
        share = random.choice(list(shares))
    elif slug.isdigit():
        share = Share.by_sid(slug)
    else:
        share = Share.by_slug(slug)
    if share:
        share.hitnum += 1
        if isinstance(share.tags, str):
            share.tags = share.tags.split()
        share.save()
        share.pop('_id')
    return share
开发者ID:anwen,项目名称:anwen,代码行数:21,代码来源:api_share.py

示例9: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
 def get(self):
     user_id = self.current_user['user_id']
     delete_share_id = self.get_argument("delete", None)
     status = self.get_argument("status", 0)
     status = int(status)
     s = self.get_argument("s", None)  # super
     if admin.is_admin(user_id):
         if delete_share_id and not s:
             admin.delete_share(delete_share_id)
         if delete_share_id and s and admin.is_superadmin(user_id):
             admin.delete_share_by_s(delete_share_id)
         # shares = Share.find({'status': {'$ne': 1}}).sort('_id', -1)
         if status == 100:
             status = {'$gt': 3}
         shares = Share.find({'status': status}).sort('_id', -1)
         if s:
             self.render('admin/super_share.html', shares=shares)
         else:
             self.render('admin/share.html', shares=shares)
     else:
         self.render('admin/join_admin.html')
开发者ID:anwen,项目名称:anwen,代码行数:23,代码来源:admin.py

示例10: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
    def get(self, node):
        page = self.get_argument("page", 1)
        share_res = Share.find({'sharetype': node}).sort(
            '_id', DESCENDING).limit(11).skip((int(page) - 1) * 11)
        pagesum = (share_res.count() + 10) / 11

        shares = []
        for share in share_res:
            user = User.by_sid(share.user_id)
            share.name = user.user_name
            share.published = time.strftime(
                '%Y-%m-%d %H:%M:%S', time.localtime(share.published))
            share.domain = user.user_domain
            share.markdown = cutter(
                markdown2.markdown(share.markdown))
            shares.append(share)

        node_info = options.node_about[node]
        self.render(
            "node.html", shares=shares,
            pagesum=pagesum, page=page, node=node, node_info=node_info)
开发者ID:randy-ran,项目名称:anwen,代码行数:23,代码来源:index.py

示例11: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
    def get(self, node='home'):
        page = self.get_argument("page", 1)
        share_res = Share.find({'status': 0}).sort(
            'score', DESCENDING).limit(11).skip((int(page) - 1) * 11)

        pagesum = (share_res.count() + 10) / 11
        shares = []
        for share in share_res:
            user = User.by_sid(share.user_id)
            share.name = user.user_name
            share.published = time.strftime(
                '%Y-%m-%d %H:%M:%S', time.localtime(share.published))
            share.domain = user.user_domain
            share.markdown = filter_tags(
                markdown2.markdown(share.markdown))[:400]
            share.gravatar = get_avatar(user.user_email, 16)
            shares.append(share)

        self.render(
            "node.html", shares=shares,
            pagesum=pagesum, page=page, node=node,
        )
开发者ID:vivekjishtu,项目名称:anwen,代码行数:24,代码来源:index.py

示例12: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
    def get(self, slug):
        share = None
        if slug.isdigit():
            share = Share.by_sid(slug)
        else:
            share = Share.by_slug(slug)
        if share:
            share.hitnum += 1
            share.save()
            share.markdown = markdown2.markdown(share.markdown)
            user = User.by_sid(share.user_id)
            share.user_name = user.user_name
            share.user_domain = user.user_domain
            tags = ''

            if share.tags:
                tags += 'tags:'
                for i in share.tags.split(' '):
                    tags += '<a href="/tag/%s">%s</a>  ' % (i, i)
            share.tags = tags
            user_id = int(
                self.current_user["user_id"]) if self.current_user else None
            like = Like.find_one(
                {'share_id': share.id, 'user_id': user_id})
            share.is_liking = bool(like.likenum % 2) if like else None
            share.is_disliking = bool(like.dislikenum % 2) if like else None
            comments = []
            comment_res = Comment.find({'share_id': share.id})
            for comment in comment_res:
                user = User.by_sid(comment.user_id)
                comment.name = user.user_name
                comment.domain = user.user_domain
                comment.gravatar = get_avatar(user.user_email, 50)
                comments.append(comment)

            if user_id:
                hit = Hit.find(
                    {'share_id': share.id},
                    {'user_id': int(self.current_user["user_id"])},
                )
                if hit.count() == 0:
                    hit = Hit
                    hit['share_id'] = share.id
                    hit['user_id'] = int(self.current_user["user_id"])
                    hit.save()
            else:
                if not self.get_cookie(share.id):
                    self.set_cookie(str(share.id), "1")
            posts = Share.find()
            suggest = []
            for post in posts:
                post.score = 100 + post.id - post.user_id + post.commentnum * 3
                post.score += post.likenum * 4 + post.hitnum * 0.01
                post.score += randint(1, 999) * 0.001
                common_tags = [i for i in post.tags.split(
                    ' ') if i in share.tags.split(' ')]
                # list(set(b1) & set(b2))
                post.score += len(common_tags)
                if post.sharetype == share.sharetype:
                    post.score += 5
                if self.current_user:
                    is_hitted = Hit.find(
                        {'share_id': share._id},
                        {'user_id': int(self.current_user["user_id"])},
                    ).count() > 0
                else:
                    is_hitted = self.get_cookie(share.id)
                if is_hitted:
                    post.score -= 50
                suggest.append(post)
            suggest.sort(key=lambda obj: obj.get('score'))
            suggest = suggest[:5]
            self.render(
                "sharee.html", share=share, comments=comments,
                suggest=suggest)
        else:
            old = 'http://blog.anwensf.com/'
            for i in options.old_links:
                if slug in i:
                    self.redirect('%s%s' % (old, i), permanent=True)
                    break
                    return
            self.redirect("/404")
开发者ID:bowu8,项目名称:anwen,代码行数:85,代码来源:share.py

示例13: get

# 需要导入模块: from db import Share [as 别名]
# 或者: from db.Share import find [as 别名]
    def get(self):
        page = self.get_argument("page", 1)
        per_page = self.get_argument("per_page", 10)
        meta_info = self.get_argument("meta_info", None)
        my_tags = self.get_argument("my_tags", None)
        tag = self.get_argument('tag', '')

        per_page = int(per_page)
        page = int(page)
        user = None
        tags = None

        token = self.request.headers.get('Authorization', '')
        if token:
            key, token = token.split()
            if key == 'token' and token:
                user_json = self.get_secure_cookie('user', token)
                if user_json:
                    user = json_decode(user_json)
        else:
            user_json = self.get_secure_cookie("user")
            if user_json:
                user = json_decode(user_json)

        print(user)
        print(my_tags)
        if user and my_tags:
            d_user = User.by_sid(user['user_id'])
            print(d_user, 1111)
            if d_user:
                print(d_user['user_tags'])
                tags = d_user['user_tags']

        vote_open = self.get_argument("vote_open", None)
        has_vote = self.get_argument("has_vote", None)
        cond = {}
        if tags:
            print('1111111111111', tags)
            cond['tags'] = {"$in": tags}

        elif tag:
            cond['tags'] = tag
        if user:
            logger.info('user_id: {}'.format(user['user_id']))
        if user and user['user_id'] in wx_admin_ids:
            cond['status'] = {'$gte': 1}
        else:
            cond['status'] = {'$gte': 1}
        if vote_open:
            if not vote_open.isdigit():
                return self.write_error(422)
            cond['vote_open'] = int(vote_open)
        if has_vote:
            cond['vote_title'] = {'$ne': ''}

        number = Share.find(cond, {'_id': 0}).count()
        shares = Share.find(cond, {'_id': 0}).sort(
            '_id', -1).limit(per_page).skip((page - 1) * per_page)
        shares = [fix_share(share) for share in shares]
        # if tag:
        #     shares = [share for share in shares if tag in share['tags']]
        meta = {}
        if meta_info and tag:
            d_tags = get_tags()
            # d_tags_parent = get_tags_parent()
            d_tags_parents = get_tags_parents()

            if tag in d_tags:
                sub_tags = []
                print(d_tags[tag])
                for name in d_tags[tag]:
                    num = Share.find({'tags': name}, {'_id': 0}).count()
                    num_recent = Share.find(
                        {'tags': name, 'published': {'$gt': time.time()-86400*30}}, {'_id': 0}).count()
                    info = {}
                    info['name'] = name
                    info['num'] = num
                    info['num_recent'] = num_recent
                    sub_tags.append(info)
                meta['sub_tags'] = sub_tags
            meta['parent_tags'] = []
            if tag in d_tags_parents:
                # hypernym
                # meta['parent_tags'].append(d_tags_parent[tag])
                meta['parent_tags'] = d_tags_parents[tag]

        self.res = list(shares)
        self.meta = meta
        print(meta)
        # number=len(self.res)
        return self.write_json(number=number)
开发者ID:anwen,项目名称:anwen,代码行数:93,代码来源:api_share.py


注:本文中的db.Share.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。