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


Python Subreddit._by_name方法代码示例

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


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

示例1: karma

# 需要导入模块: from subreddit import Subreddit [as 别名]
# 或者: from subreddit.Subreddit import _by_name [as 别名]
    def karma(self, kind, sr=None):
        from subreddit import Subreddit

        suffix = "_" + kind + "_karma"

        # if no sr, return the sum
        if sr is None:
            total = 0
            for k, v in self._t.iteritems():
                if k.endswith(suffix):
                    if kind == "link":
                        try:
                            karma_sr_name = k[0 : k.rfind(suffix)]
                            karma_sr = Subreddit._by_name(karma_sr_name)
                            multiplier = karma_sr.post_karma_multiplier
                        except NotFound:
                            multiplier = 1
                    else:
                        multiplier = 1
                    total += v * multiplier
            return total
        else:
            try:
                return getattr(self, sr.name + suffix)
            except AttributeError:
                # if positive karma elsewhere, you get min_up_karma
                if self.karma(kind) > 0:
                    return g.MIN_UP_KARMA
                else:
                    return 0
开发者ID:Kenneth-Chen,项目名称:lesswrong,代码行数:32,代码来源:account.py

示例2: karma_ups_downs

# 需要导入模块: from subreddit import Subreddit [as 别名]
# 或者: from subreddit.Subreddit import _by_name [as 别名]
    def karma_ups_downs(self, kind, sr = None):
        # NOTE: There is a legacy inconsistency in this method. If no subreddit
        # is specified, karma from all subreddits will be totaled, with each
        # scaled according to its karma multiplier before being summed. But if
        # a subreddit IS specified, the return value will NOT be scaled.

        assert kind in ('link', 'comment', 'adjustment')

        from subreddit import Subreddit  # prevent circular import

        # If getting karma for a single sr, it's easy
        if sr is not None:
            ups = getattr(self, 'karma_ups_{0}_{1}'.format(kind, sr.name), 0)
            downs = getattr(self, 'karma_downs_{0}_{1}'.format(kind, sr.name), 0)
            return (ups, downs)

        # Otherwise, loop through attributes and sum all karmas
        totals = [0, 0]
        for k, v in self._t.iteritems():
            for pre, idx in (('karma_ups_' + kind + '_', 0),
                              ('karma_downs_' + kind + '_', 1)):
                if k.startswith(pre):
                    karma_sr_name = k[len(pre):]
                    index = idx
                    break
            else:
                continue

            multiplier = 1
            if kind == 'link':
                try:
                    karma_sr = Subreddit._by_name(karma_sr_name)
                    multiplier = karma_sr.post_karma_multiplier
                except NotFound:
                    pass
            totals[index] += v * multiplier
        return tuple(totals)
开发者ID:arichard4,项目名称:eaforum,代码行数:39,代码来源:account.py


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