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


Python Subreddit._byID方法代码示例

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


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

示例1: new_report

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def new_report(thing):
    if isinstance(thing, Link):
        sr = Subreddit._byID(thing.sr_id)
        add_queries([get_reported_links(sr)], insert_items = thing)
    elif isinstance(thing, Comment):
        sr = Subreddit._byID(thing.sr_id)
        add_queries([get_reported_comments(sr)], insert_items = thing)
开发者ID:rram,项目名称:reddit,代码行数:9,代码来源:queries.py

示例2: get_links

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
    def get_links(cls, event_id):
        link_ids = cls._get_related_link_ids(event_id)
        links = Link._byID(link_ids, data=True, return_dict=False)
        links.sort(key=lambda L: L.num_comments, reverse=True)

        sr_ids = set(L.sr_id for L in links)
        subreddits = Subreddit._byID(sr_ids, data=True)

        wrapped = []
        for link in links:
            w = Wrapped(link)

            if w._spam or w._deleted:
                continue

            if not getattr(w, "allow_liveupdate", True):
                continue

            w.subreddit = subreddits[link.sr_id]

            # ideally we'd check if the user can see the subreddit, but by
            # doing this we keep everything user unspecific which makes caching
            # easier.
            if w.subreddit.type == "private":
                continue

            comment_label = ungettext("comment", "comments", link.num_comments)
            w.comments_label = strings.number_label % dict(
                num=link.num_comments, thing=comment_label)

            wrapped.append(w)
        return wrapped
开发者ID:binarycoder,项目名称:reddit-plugin-liveupdate,代码行数:34,代码来源:pages.py

示例3: get_reply_to_address

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def get_reply_to_address(message):
    """Construct a reply-to address that encodes the message id.

    The address is of the form:
        zendeskreply+{message_id36}-{email_mac}

    where the mac is generated from {message_id36} using the
    `modmail_email_secret`

    The reply address should be configured with the inbound email service so
    that replies to our messages are routed back to the app somehow. For mailgun
    this involves adding a Routes filter for messages sent to
    "zendeskreply\+*@". to be forwarded to POST /api/zendeskreply.

    """

    # all email replies are treated as replies to the first message in the
    # conversation. this is to get around some peculiarities of zendesk
    if message.first_message:
        first_message = Message._byID(message.first_message, data=True)
    else:
        first_message = message
    email_id = first_message._id36

    email_mac = hmac.new(
        g.secrets['modmail_email_secret'], email_id, hashlib.sha256).hexdigest()
    reply_id = "zendeskreply+{email_id}-{email_mac}".format(
        email_id=email_id, email_mac=email_mac)

    sr = Subreddit._byID(message.sr_id, data=True)
    return "r/{subreddit} mail <{reply_id}@{domain}>".format(
        subreddit=sr.name, reply_id=reply_id, domain=g.modmail_email_domain)
开发者ID:AHAMED750,项目名称:reddit,代码行数:34,代码来源:message_to_email.py

示例4: update_karmas

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def update_karmas():
    for pair in to_update():
        user = Account._byID(pair[0], True)
        sr = Subreddit._byID(pair[1], True)

        print user.name, sr.name
        user.incr_karma('comment', sr, 20)
开发者ID:ArslanRafique,项目名称:reddit,代码行数:9,代码来源:update_karmas.py

示例5: get_adzerk_promo

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def get_adzerk_promo(user, site):
    srids = promote.has_live_promos(user, site)
    if not srids:
        return

    if '' in srids:
        srnames = [Frontpage.name]
        srids.remove('')
    else:
        srnames = []

    srs = Subreddit._byID(srids, data=True, return_dict=False)
    srnames.extend([sr.name for sr in srs])
    response = adzerk_request(srnames)

    if not response:
        return

    promo_tuples = [promote.PromoTuple(response.link, 1., response.campaign)]
    builder = CampaignBuilder(promo_tuples,
                              keep_fn=organic.keep_fresh_links)
    promoted_links = builder.get_items()[0]
    if promoted_links:
        w = promoted_links[0]
        w.adserver_imp_pixel = response.imp_pixel
        w.adserver_click_url = response.click_url
        return w
开发者ID:bsimpson63,项目名称:reddit-plugin-adzerkpromo,代码行数:29,代码来源:adzerkpromo.py

示例6: normalized_hot_cached

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def normalized_hot_cached(sr_ids):
    results = []
    srs = Subreddit._byID(sr_ids, data = True, return_dict = False)
    for sr in srs:
        #items = get_hot(sr)
        items = filter(lambda l: l._date > utils.timeago('%d day' % g.HOT_PAGE_AGE),
                       get_hot(sr))

        if not items:
            continue

        top_score = max(items[0]._hot, 1)
        
        top, rest = items[:2], items[2:]

        if top:
            normals = [l._hot / top_score for l in top]
            results.extend((l, random.choice(normals)) for l in top)
            #random.shuffle(normals)
            #results.extend((l, normals.pop()) for l in top)
        
        if rest:
            results.extend((l, l._hot / top_score) for l in rest)

    results.sort(key = lambda x: (x[1], x[0]._hot), reverse = True)
    return [l[0]._fullname for l in results]
开发者ID:cmak,项目名称:reddit,代码行数:28,代码来源:normalized_hot.py

示例7: new_promotion

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def new_promotion(is_self, title, content, author, ip):
    """
    Creates a new promotion with the provided title, etc, and sets it
    status to be 'unpaid'.
    """
    sr = Subreddit._byID(Subreddit.get_promote_srid())
    l = Link._submit(
        is_self=is_self,
        title=title,
        content=content,
        author=author,
        sr=sr,
        ip=ip,
    )

    l.promoted = True
    l.disable_comments = False
    l.sendreplies = True
    PromotionLog.add(l, 'promotion created')

    update_promote_status(l, PROMOTE_STATUS.unpaid)

    # the user has posted a promotion, so enable the promote menu unless
    # they have already opted out
    if author.pref_show_promote is not False:
        author.pref_show_promote = True
        author._commit()

    # notify of new promo
    emailer.new_promo(l)
    return l
开发者ID:pra85,项目名称:reddit,代码行数:33,代码来源:promote.py

示例8: get_reported

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def get_reported(sr):
    if isinstance(sr, ModContribSR):
        srs = Subreddit._byID(sr.sr_ids(), return_dict=False)
        results = [get_reported_links(sr) for sr in srs]
        return merge_results(*results)
    else:
        return get_reported_links(sr)
开发者ID:denrobapps,项目名称:Reddit-VM,代码行数:9,代码来源:queries.py

示例9: new_promotion

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def new_promotion(title, url, selftext, user, ip):
    """
    Creates a new promotion with the provided title, etc, and sets it
    status to be 'unpaid'.
    """
    sr = Subreddit._byID(get_promote_srid())
    l = Link._submit(title, url, user, sr, ip)
    l.promoted = True
    l.disable_comments = False
    PromotionLog.add(l, 'promotion created')

    if url == 'self':
        l.url = l.make_permalink_slow()
        l.is_self = True
        l.selftext = selftext

    l._commit()

    # set the status of the link, populating the query queue
    if c.user_is_sponsor or user.trusted_sponsor:
        set_promote_status(l, PROMOTE_STATUS.accepted)
    else:
        set_promote_status(l, PROMOTE_STATUS.unpaid)

    # the user has posted a promotion, so enable the promote menu unless
    # they have already opted out
    if user.pref_show_promote is not False:
        user.pref_show_promote = True
        user._commit()

    # notify of new promo
    emailer.new_promo(l)
    return l
开发者ID:AD42,项目名称:reddit,代码行数:35,代码来源:promote.py

示例10: migrate_scan_adjustments

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
 def migrate_scan_adjustments(self):
     adjs = KarmaAdjustment._query(data=True)
     for adj in adjs:
         sr = Subreddit._byID(adj.sr_id)
         gravity = 'ups' if adj.amount >= 0 else 'downs'
         key = 'karma_{0}_adjustment_{1}'.format(gravity, sr.name)
         self.new_values[adj.account_id][key] += abs(adj.amount)
开发者ID:camspiers,项目名称:lesswrong,代码行数:9,代码来源:recalc_karma.py

示例11: new_promotion

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def new_promotion(title, url, selftext, user, ip):
    """
    Creates a new promotion with the provided title, etc, and sets it
    status to be 'unpaid'.
    """
    sr = Subreddit._byID(get_promote_srid())
    l = Link._submit(title, url, user, sr, ip)
    l.promoted = True
    l.disable_comments = False
    PromotionLog.add(l, "promotion created")

    if url == "self":
        l.url = l.make_permalink_slow()
        l.is_self = True
        l.selftext = selftext

    l._commit()

    update_promote_status(l, PROMOTE_STATUS.unpaid)

    # the user has posted a promotion, so enable the promote menu unless
    # they have already opted out
    if user.pref_show_promote is not False:
        user.pref_show_promote = True
        user._commit()

    # notify of new promo
    emailer.new_promo(l)
    return l
开发者ID:j2p2,项目名称:reddit,代码行数:31,代码来源:promote.py

示例12: process_message

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
    def process_message(msgs, chan):
        """Update get_links(), the Links by Subreddit precomputed query.

        get_links() is a CachedResult which is stored in permacache. To
        update these objects we need to do a read-modify-write which requires
        obtaining a lock. Sharding these updates by subreddit allows us to run
        multiple consumers (but ideally just one per shard) to avoid lock
        contention.

        """

        from r2.lib.db.queries import add_queries, get_links

        link_names = {msg.body for msg in msgs}
        links = Link._by_fullname(link_names, return_dict=False)
        print 'Processing %r' % (links,)

        links_by_sr_id = defaultdict(list)
        for link in links:
            links_by_sr_id[link.sr_id].append(link)

        srs_by_id = Subreddit._byID(links_by_sr_id.keys(), stale=True)

        for sr_id, links in links_by_sr_id.iteritems():
            with g.stats.get_timer("link_vote_processor.subreddit_queries"):
                sr = srs_by_id[sr_id]
                add_queries(
                    queries=[get_links(sr, sort, "all") for sort in SORTS],
                    insert_items=links,
                )
开发者ID:13steinj,项目名称:reddit,代码行数:32,代码来源:voting.py

示例13: update_flair_counts

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def update_flair_counts():
    flairs = Counter()
    user_ids = []

    sr = Subreddit._byID(g.live_config["thebutton_srid"], data=True)
    raw = AccountsActiveBySR._cf.xget(sr._id36)
    for uid, _ in raw:
        user_ids.append(uid)

    for user_chunk in in_chunks(user_ids, size=100):
        users = Account._byID36(user_chunk, data=True, return_dict=False)
        for user in users:
            flair = user.flair_css_class(sr._id)
            if not flair:
                if user._date < ACCOUNT_CREATION_CUTOFF:
                    flair = "no-press"
                else:
                    flair = "cant-press"

            flairs[flair] += 1

    if 'cheater' in flairs:
        del flairs['cheater']

    sr.flair_counts = sorted(
        flairs.iteritems(),
        key=lambda x: 'z' if x[0] == 'no-press' else x[0],
        reverse=True)
    sr._commit()
开发者ID:imclab,项目名称:reddit-plugin-thebutton,代码行数:31,代码来源:scripts.py

示例14: __init__

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
    def __init__(self):
        Wrapped.__init__(self)

        my_reddits = []
        sr_ids = Subreddit.user_subreddits(c.user if c.user_is_loggedin else None)
        if sr_ids:
            my_reddits = Subreddit._byID(sr_ids, True,
                                         return_dict = False)
            my_reddits.sort(key = lambda sr: sr.name.lower())

        drop_down_buttons = []    
        for sr in my_reddits:
            drop_down_buttons.append(SubredditButton(sr))

        #leaving the 'home' option out for now
        #drop_down_buttons.insert(0, NamedButton('home', sr_path = False,
        #                                        css_class = 'top-option',
        #                                        dest = '/'))
        drop_down_buttons.append(NamedButton('edit', sr_path = False,
                                             css_class = 'bottom-option',
                                             dest = '/reddits/'))
        self.sr_dropdown = SubredditMenu(drop_down_buttons,
                                         title = _('my reddits'),
                                         type = 'srdrop')

    
        pop_reddits = Subreddit.default_srs(c.content_langs, limit = 30)        
        buttons = [SubredditButton(sr) for sr in c.recent_reddits]
        for sr in pop_reddits:
            if sr not in c.recent_reddits:
                buttons.append(SubredditButton(sr))
    
        self.sr_bar = NavMenu(buttons, type='flatlist', separator = '-',
                                        _id = 'sr-bar')
开发者ID:vin,项目名称:reddit,代码行数:36,代码来源:pages.py

示例15: get_spam

# 需要导入模块: from r2.models import Subreddit [as 别名]
# 或者: from r2.models.Subreddit import _byID [as 别名]
def get_spam(sr):
    if isinstance(sr, ModContribSR):
        srs = Subreddit._byID(sr.sr_ids, return_dict=False)
        results = [get_spam_links(sr) for sr in srs]
        return merge_results(*results)
    else:
        return merge_results(get_spam_links(sr), get_spam_comments(sr))
开发者ID:ap0rnnstar,项目名称:reddit,代码行数:9,代码来源:queries.py


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