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


Python Link._by_fullname方法代码示例

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


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

示例1: _handle_check_edits

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
    def _handle_check_edits(payload):
        existing = Link._by_fullname(payload["link"], data=True)
        creative = creatives_service.get_creative(existing)

        link = utils.dfp_creative_to_link(
            creative, link=Link._by_fullname(payload["link"], data=True))

        link.dfp_checking_edits = False
        link._commit()
开发者ID:13steinj,项目名称:reddit-plugin-dfp,代码行数:11,代码来源:queue.py

示例2: _handle_adzerk

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
 def _handle_adzerk(msg):
     data = json.loads(msg.body)
     g.log.debug('data: %s' % data)
     action = data.get('action')
     if action == 'deactivate_link':
         link = Link._by_fullname(data['link'], data=True)
         _deactivate_link(link)
     elif action == 'deactivate_campaign':
         link = Link._by_fullname(data['link'], data=True)
         campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
         _deactivate_campaign(link, campaign)
     elif action == 'update_adzerk':
         link = Link._by_fullname(data['link'], data=True)
         campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
         _update_adzerk(link, campaign)
开发者ID:alienth,项目名称:reddit-plugin-adzerk,代码行数:17,代码来源:adzerkpromote.py

示例3: bid_history

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
    def bid_history(cls, start_date, end_date = None, account_id = None):
        from r2.models import Link
        from r2.lib import promote
        start_date = to_date(start_date)
        end_date   = to_date(end_date)
        q = cls.query()
        q = q.filter(and_(cls.date >= start_date, cls.date < end_date))
        q = list(q)

        links = Link._by_fullname([x.thing_name for x in q], data=True)

        d = start_date
        res = []
        while d < end_date:
            bid = 0
            refund = 0
            for i in q:
                if d == i.date:
                    l = links[i.thing_name]
                    if (not promote.is_rejected(l) and 
                        not promote.is_unpaid(l) and 
                        not l._deleted and 
                        i.promo_idx in getattr(l, 'campaigns', {})):
                        
                        camp = l.campaigns[i.promo_idx]
                        bid += i.bid
                        refund += i.bid if camp[-1] <= 0 else 0
            res.append([d, bid, refund])
            d += datetime.timedelta(1)
        return res
开发者ID:Jeerok,项目名称:reddit,代码行数:32,代码来源:bidding.py

示例4: set_recent_clicks

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
def set_recent_clicks():
    c.recent_clicks = []
    if not c.user_is_loggedin:
        return

    click_cookie = read_user_cookie('recentclicks2')
    if click_cookie:
        if valid_click_cookie(click_cookie):
            names = [ x for x in UniqueIterator(click_cookie.split(',')) if x ]

            if len(names) > 5:
                names = names[:5]
                set_user_cookie('recentclicks2', ','.join(names))
            #eventually this will look at the user preference
            names = names[:5]

            try:
                c.recent_clicks = Link._by_fullname(names, data=True,
                                                    return_dict=False)
            except NotFound:
                # clear their cookie because it's got bad links in it
                set_user_cookie('recentclicks2', '')
        else:
            #if the cookie wasn't valid, clear it
            set_user_cookie('recentclicks2', '')
开发者ID:ChrisCinelli,项目名称:reddit,代码行数:27,代码来源:reddit_base.py

示例5: thing_lookup

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
    def thing_lookup(self, tuples):
        links = Link._by_fullname([t.link for t in tuples], data=True, return_dict=True, stale=self.stale)

        return [
            Storage({"thing": links[t.link], "_id": links[t.link]._id, "weight": t.weight, "campaign": t.campaign})
            for t in tuples
        ]
开发者ID:pombredanne,项目名称:reddit,代码行数:9,代码来源:builder.py

示例6: process_message

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

        get_domain_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 domain 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_domain_links

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

        links_by_domain = defaultdict(list)
        for link in links:
            parsed = UrlParser(link.url)

            # update the listings for all permutations of the link's domain
            for domain in parsed.domain_permutations():
                links_by_domain[domain].append(link)

        for d, links in links_by_domain.iteritems():
            with g.stats.get_timer("link_vote_processor.domain_queries"):
                add_queries(
                    queries=[
                        get_domain_links(d, sort, "all") for sort in SORTS],
                    insert_items=links,
                )
开发者ID:13steinj,项目名称:reddit,代码行数:34,代码来源:voting.py

示例7: _handle_adzerk

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
    def _handle_adzerk(msg):
        data = json.loads(msg.body)
        g.log.debug('data: %s' % data)

        action = data.get('action')

        if action == 'deactivate_orphaned_flight':
            _deactivate_orphaned_flight(data['flight'])
            return

        link = Link._by_fullname(data['link'], data=True)
        if data['campaign']:
            campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
        else:
            campaign = None

        if action == 'update_adzerk':
            if 'triggered_by' in data and data['triggered_by'] is not None:
                triggered_by = Account._by_fullname(data['triggered_by'], data=True)
            else:
                triggered_by = None

            _update_adzerk(link, campaign, triggered_by)

        elif action == 'deactivate_overdelivered':
            _deactivate_overdelivered(link, campaign)
开发者ID:bsdo64,项目名称:reddit-plugin-adzerk,代码行数:28,代码来源:adzerkpromote.py

示例8: thing_lookup

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
    def thing_lookup(self, tuples):
        links = Link._by_fullname([t.link for t in tuples], data=True,
                                  return_dict=True, stale=self.stale)

        return [Storage({'thing': links[t.link],
                         '_id': links[t.link]._id,
                         'weight': t.weight,
                         'campaign': t.campaign}) for t in tuples]
开发者ID:jonoirwinrsa,项目名称:reddit,代码行数:10,代码来源:builder.py

示例9: send_account_summary_email

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
def send_account_summary_email(account_thing_id, verbose=False, send_email=send_email):
    account = Account._byID(account_thing_id, data=True)
    if not should_send_activity_summary_email(account):
        return

    # if we've never sent an email, only tell about the last 24 hours
    a_day_ago = datetime.datetime.now(pytz.utc) - datetime.timedelta(hours=24)
    if getattr(account, 'last_email_sent_at', None) is None:
        account.last_email_sent_at = a_day_ago

    c.content_langs = 'en-US'

    # Find all the "active" links for this user.  Frontpage uses the c.user global
    # to find the right subreddits for the current user
    c.user = account
    c.user_is_loggedin = True
    thing_ids = []
    for link in Frontpage.get_links('active', 'all'):
        thing_ids.append(link)
    active_links_hash = Link._by_fullname(thing_ids, data=True)

    active_links = [active_links_hash[t_id] for t_id in thing_ids if active_links_hash[t_id]._active > account.last_email_sent_at]
    idx = 0
    for ll in active_links:
        idx += 1
        ll.num = idx 

    # Find all new spaces created since we last sent the user an email
    new_spaces = list(fetch_things2(Subreddit._query(
        Subreddit.c._date > account.last_email_sent_at,
        sort=asc('_date'))))

    # don't bother sending email if there's noting to report.
    if len(new_spaces) == 0 and len(active_links) == 0:
        return

    # Get the date and time
    now = datetime.datetime.now(pytz.timezone('US/Eastern'))
    date_string = now.strftime("%A %B %d, %Y")
    time_string = now.strftime("%I:%M %p")

    # Render the template
    html_email_template = g.mako_lookup.get_template('summary_email.html')
    html_body = html_email_template.render(
        last_email_sent_at=account.last_email_sent_at,
        new_spaces=new_spaces, 
        active_links=active_links,
        date_string=date_string,
        time_string=time_string)

    # with open('out.html', 'w') as ff:
    #     ff.write(html_body)
    if verbose:
        print "sending email to %s" % (account.email,)
    send_email(account.email, html_body, date_string)

    account.last_email_sent_at = datetime.datetime.now(pytz.utc)
    account._commit()
开发者ID:caseypatrickdriscoll,项目名称:reddit,代码行数:60,代码来源:summary_email.py

示例10: get_rising_items

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
def get_rising_items(omit_sr_ids, count=4):
    """Get links that are rising right now."""
    all_rising = rising.get_all_rising()
    candidate_sr_ids = {sr_id for link, score, sr_id in all_rising}.difference(omit_sr_ids)
    link_fullnames = [link for link, score, sr_id in all_rising if sr_id in candidate_sr_ids]
    link_fullnames_to_show = random_sample(link_fullnames, count)
    rising_links = Link._by_fullname(link_fullnames_to_show, return_dict=False, data=True)
    rising_items = [ExploreItem(TYPE_RISING, "ris", Subreddit._byID(l.sr_id), l) for l in rising_links]
    return rising_items
开发者ID:Shilohtd,项目名称:reddit,代码行数:11,代码来源:recommender.py

示例11: get_hot_items

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
def get_hot_items(srs, item_type, src):
    """Get hot links from specified srs."""
    hot_srs = {sr._id: sr for sr in srs}  # for looking up sr by id
    hot_link_fullnames = normalized_hot(sr._id for sr in srs)
    hot_links = Link._by_fullname(hot_link_fullnames, return_dict=False)
    hot_items = []
    for l in hot_links:
        hot_items.append(ExploreItem(item_type, src, hot_srs[l.sr_id], l))
    return hot_items
开发者ID:0xcd03,项目名称:reddit,代码行数:11,代码来源:recommender.py

示例12: get_hot

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
def get_hot(sr):
    """Get the hottest links for a subreddit. If g.use_query_cache is
    True, it'll use the query cache, otherwise it'll use cached_query()
    from above."""
    q = sr.get_links('hot', 'all')
    if isinstance(q, Query):
        return cached_query(q, sr)
    else:
        return Link._by_fullname(list(q)[:150], return_dict = False)
开发者ID:AndrewHay,项目名称:lesswrong,代码行数:11,代码来源:normalized_hot.py

示例13: _handle_upsert_campaign

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
def _handle_upsert_campaign(payload):
    link = Link._by_fullname(payload["link"], data=True)
    campaign = PromoCampaign._by_fullname(payload["campaign"], data=True)
    owner = Account._byID(campaign.owner_id)

    lineitem = lineitems_service.upsert_lineitem(owner, campaign)
    creative = creatives_service.get_creative(link)

    lineitems_service.associate_with_creative(
        lineitem=lineitem, creative=creative)
开发者ID:dwick,项目名称:reddit-plugin-dfp,代码行数:12,代码来源:queue.py

示例14: _run

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
 def _run(msgs, chan):
     items = [json.loads(msg.body) for msg in msgs]
     if QUEUE_ALL in items:
         # QUEUE_ALL is just an indicator to run make_daily_promotions.
         # There's no promotion log to update in this case.
         print "Received %s QUEUE_ALL message(s)" % items.count(QUEUE_ALL)
         items = [i for i in items if i != QUEUE_ALL]
     make_daily_promotions()
     links = Link._by_fullname([i["link"] for i in items])
     for item in items:
         PromotionLog.add(links[item['link']],
                          "Finished remaking current promotions (this link "
                          "was: %(message)s" % item)
开发者ID:AD42,项目名称:reddit,代码行数:15,代码来源:promote.py

示例15: _handle_adzerk

# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _by_fullname [as 别名]
    def _handle_adzerk(msg):
        data = json.loads(msg.body)
        g.log.debug('data: %s' % data)

        action = data.get('action')
        link = Link._by_fullname(data['link'], data=True)
        if data['campaign']:
            campaign = PromoCampaign._by_fullname(data['campaign'], data=True)
        else:
            campaign = None

        if action == 'update_adzerk':
            _update_adzerk(link, campaign)
        elif action == 'deactivate_overdelivered':
            _deactivate_overdelivered(link, campaign)
开发者ID:curioussavage,项目名称:reddit-plugin-adzerk,代码行数:17,代码来源:adzerkpromote.py


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