• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python organic.organic_links函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中r2.lib.organic.organic_links函数的典型用法代码示例。如果您正苦于以下问题:Python organic_links函数的具体用法?Python organic_links怎么用?Python organic_links使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: organic

    def organic(self):
        o_links, pos = organic.organic_links(c.user)
        if o_links:
            # get links in proximity to pos
            l = min(len(o_links) - 3, 8)
            disp_links = [o_links[(i + pos) % len(o_links)] for i in xrange(-2, l)]

            def keep_fn(item):
                return item.likes is None and item.keep_item(item)

            b = IDBuilder(disp_links, wrap=self.builder_wrapper, skip=True, keep_fn=keep_fn)
            o = OrganicListing(
                b,
                org_links=o_links,
                visible_link=o_links[pos],
                max_num=self.listing_obj.max_num,
                max_score=self.listing_obj.max_score,
            ).listing()

            if len(o.things) > 0:
                # only pass through a listing if the links made it
                # through our builder
                organic.update_pos(pos + 1)

                return o
开发者ID:kevinrose,项目名称:diggit,代码行数:25,代码来源:listingcontroller.py


示例2: make_spotlight

    def make_spotlight(self):
        """Build the Spotlight.

        The frontpage gets a Spotlight box that contains promoted and organic
        links from the user's subscribed subreddits and promoted links targeted
        to the frontpage. If the user has disabled ads promoted links will not
        be shown.

        The content of the Spotlight box is a bit tricky because a single
        version of the frontpage is cached and displayed to all logged out
        users. Because of the caching we must include many promoted links and
        select one to display on the client side. Otherwise, each logged out
        user would see the same promoted link and we would not get the desired
        distribution of promoted link views. Most of the promoted links are
        included as stubs to reduce the size of the page. When a promoted link
        stub is selected by the lottery the full link is fetched and displayed.

        There are only ~1000 cache resets per day so it is necessary to use
        a large subset of the eligible promoted links when choosing stubs for
        the Spotlight box. Using 100 stubs works great when there are fewer than
        100 possible promoted links and allows room for growth.

        """

        organic_fullnames = organic.organic_links(c.user)
        promoted_links = []

        # If prefs allow it, mix in promoted links and sr discovery content
        if (c.user.pref_show_sponsors or not c.user.gold) and g.live_config["sr_discovery_links"]:
            organic_fullnames.extend(g.live_config["sr_discovery_links"])

        show_promo = False
        srnames = []
        if c.user.pref_show_sponsors or not c.user.gold:
            srs = promote.srs_with_live_promos(c.user, c.site)
            if srs:
                if (c.user_is_loggedin and random.random() > 0.5) or not c.user_is_loggedin:
                    srnames = [sr.name for sr in srs]
                    show_promo = True

        random.shuffle(organic_fullnames)
        organic_fullnames = organic_fullnames[:10]
        b = IDBuilder(organic_fullnames, wrap=self.builder_wrapper, keep_fn=organic.keep_fresh_links, skip=True)
        organic_links = b.get_items()[0]

        has_subscribed = c.user.has_subscribed
        interestbar_prob = g.live_config["spotlight_interest_sub_p" if has_subscribed else "spotlight_interest_nosub_p"]
        interestbar = InterestBar(has_subscribed)

        s = SpotlightListing(
            organic_links=organic_links,
            interestbar=interestbar,
            interestbar_prob=interestbar_prob,
            show_promo=show_promo,
            srnames=srnames,
            max_num=self.listing_obj.max_num,
            max_score=self.listing_obj.max_score,
        ).listing()
        return s
开发者ID:hexacyanide,项目名称:reddit,代码行数:59,代码来源:listingcontroller.py


示例3: organic

    def organic(self):
        o_links, pos = organic.organic_links(c.user)
        if o_links:
            # get links in proximity to pos
            disp_links = [o_links[(i + pos) % len(o_links)] for i in xrange(-2, 8)]

            b = IDBuilder(disp_links,
                          wrap = self.builder_wrapper)
            o = OrganicListing(b,
                               org_links = o_links,
                               visible_link = o_links[pos],
                               max_num = self.listing_obj.max_num,
                               max_score = self.listing_obj.max_score)
            organic.update_pos(c.user, (pos + 1) % len(o_links))
            return o.listing()
开发者ID:cmak,项目名称:reddit,代码行数:15,代码来源:listingcontroller.py


示例4: make_spotlight

    def make_spotlight(self):
        """Build the Spotlight.

        The frontpage gets a Spotlight box that contains promoted and organic
        links from the user's subscribed subreddits and promoted links targeted
        to the frontpage. If the user has disabled ads promoted links will not
        be shown. Promoted links are requested from the adserver client-side.

        """

        organic_fullnames = organic.organic_links(c.user)
        promoted_links = []

        show_promo = False
        srnames = []
        can_show_promo = c.user.pref_show_sponsors or not c.user.gold
        try_show_promo = ((c.user_is_loggedin and random.random() > 0.5) or
                          not c.user_is_loggedin)

        if can_show_promo and try_show_promo:
            srnames = promote.srnames_with_live_promos(c.user, c.site)
            if srnames:
                show_promo = True

        random.shuffle(organic_fullnames)
        organic_fullnames = organic_fullnames[:10]
        b = IDBuilder(organic_fullnames,
                      wrap=self.builder_wrapper,
                      keep_fn=organic.keep_fresh_links,
                      skip=True)
        organic_links = b.get_items()[0]

        has_subscribed = c.user.has_subscribed
        interestbar_prob = g.live_config['spotlight_interest_sub_p'
                                         if has_subscribed else
                                         'spotlight_interest_nosub_p']
        interestbar = InterestBar(has_subscribed)

        s = SpotlightListing(organic_links=organic_links,
                             interestbar=interestbar,
                             interestbar_prob=interestbar_prob,
                             show_promo=show_promo,
                             srnames=srnames,
                             max_num = self.listing_obj.max_num,
                             max_score = self.listing_obj.max_score).listing()
        return s
开发者ID:aburan28,项目名称:reddit,代码行数:46,代码来源:listingcontroller.py


示例5: organic

    def organic(self):
        o_links, pos, calculation_key = organic.organic_links(c.user)
        if o_links:
            # get links in proximity to pos
            l = min(len(o_links) - 3, 8)
            disp_links = [o_links[(i + pos) % len(o_links)] for i in xrange(-2, l)]

            b = IDBuilder(disp_links, wrap = self.builder_wrapper)
            o = OrganicListing(b,
                               org_links = o_links,
                               visible_link = o_links[pos],
                               max_num = self.listing_obj.max_num,
                               max_score = self.listing_obj.max_score).listing()

            if len(o.things) > 0:
                # only pass through a listing if the links made it
                # through our builder
                organic.update_pos(pos+1, calculation_key)

                return o
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:20,代码来源:listingcontroller.py


示例6: spotlight

    def spotlight(self):
        if (isinstance(c.site, DefaultSR)
            and (not c.user_is_loggedin
                 or (c.user_is_loggedin and c.user.pref_organic))):

            spotlight_links = organic.organic_links(c.user)
            pos = organic_pos()

            if not spotlight_links:
                pos = 0
            elif pos != 0:
                pos = pos % len(spotlight_links)

            if c.user.pref_show_sponsors or not c.user.gold:
                spotlight_links, pos = promote.insert_promoted(spotlight_links, pos)
            trial = populate_spotlight()

            # Need to do this again, because if there was a duplicate removed,
            # pos might be pointing outside the list.
            if not spotlight_links:
                pos = 0
            elif pos != 0:
                pos = pos % len(spotlight_links)

            if trial:
                spotlight_links.insert(pos, trial._fullname)

            if not spotlight_links:
                return None

            # get links in proximity to pos
            num_tl = len(spotlight_links)
            if num_tl <= 3:
                disp_links = spotlight_links
            else:
                left_side = max(-1, min(num_tl - 3, 8))
                disp_links = [spotlight_links[(i + pos) % num_tl]
                              for i in xrange(-2, left_side)]

            def trial_keep_fn(item):
                if trial and trial._fullname == item._fullname:
                    return True
                return organic.keep_fresh_links(item)

            def trial_wrap(item):
               if item is trial:
                   w = Wrapped(item)
                   w.trial_mode = True
                   w.render_class = LinkOnTrial
                   return w
               return self.builder_wrapper(item)

            b = IDBuilder(disp_links,
                          wrap = trial_wrap if trial else self.builder_wrapper,
                          num = organic.organic_length,
                          skip = True,
                          keep_fn = trial_keep_fn if trial else organic.keep_fresh_links)

            try:
                vislink = spotlight_links[pos]
            except IndexError:
                g.log.error("spotlight_links = %r" % spotlight_links)
                g.log.error("pos = %d" % pos)
                raise

            s = SpotlightListing(b, spotlight_links = spotlight_links,
                                 visible_link = vislink,
                                 max_num = self.listing_obj.max_num,
                                 max_score = self.listing_obj.max_score).listing()

            if len(s.things) > 0:
                # only pass through a listing if the links made it
                # through our builder
                organic.update_pos(pos+1)
                return s

        # no organic box on a hot page, then show a random promoted link
        elif not isinstance(c.site, DefaultSR) and c.user.pref_show_sponsors:
            link_ids = randomized_promotion_list(c.user, c.site)
            if link_ids:
                res = wrap_links(link_ids, wrapper = self.builder_wrapper,
                                 num = 1, keep_fn = lambda x: x.fresh, 
                                 skip = True)
                if res.things:
                    return res
开发者ID:donslice,项目名称:reddit,代码行数:85,代码来源:listingcontroller.py


示例7: make_spotlight

    def make_spotlight(self):
        """Build the Spotlight.

        The frontpage gets a Spotlight box that contains promoted and organic
        links from the user's subscribed subreddits and promoted links targeted
        to the frontpage. If the user has disabled ads promoted links will not
        be shown.

        The content of the Spotlight box is a bit tricky because a single
        version of the frontpage is cached and displayed to all logged out
        users. Because of the caching we must include many promoted links and
        select one to display on the client side. Otherwise, each logged out
        user would see the same promoted link and we would not get the desired
        distribution of promoted link views. Most of the promoted links are
        included as stubs to reduce the size of the page. When a promoted link
        stub is selected by the lottery the full link is fetched and displayed.

        There are only ~1000 cache resets per day so it is necessary to use
        a large subset of the eligible promoted links when choosing stubs for
        the Spotlight box. Using 100 stubs works great when there are fewer than
        100 possible promoted links and allows room for growth.

        """

        organic_fullnames = organic.organic_links(c.user)
        promoted_links = []

        # If prefs allow it, mix in promoted links and sr discovery content
        if c.user.pref_show_sponsors or not c.user.gold:
            if g.live_config['sr_discovery_links']:
                organic_fullnames.extend(g.live_config['sr_discovery_links'])

            n_promoted = 100
            n_build = 1 if c.user_is_loggedin else 10
            picker = (promote.lottery_promoted_links if c.user_is_loggedin else
                      promote.sample_promoted_links)
            promo_tuples = picker(c.user, c.site, n=n_promoted)

            if not c.user_is_loggedin:
                promo_tuples.sort(key=lambda t: t.weight, reverse=True)

            b = CampaignBuilder(
                    promo_tuples,
                    wrap=self.builder_wrapper,
                    keep_fn=organic.keep_fresh_links,
                    num=n_build,
                    skip=True,
            )
            promoted_links, first, last, before, after = b.get_items()
            if promoted_links and last:
                lookup = {t.campaign: i for i, t in enumerate(promo_tuples)}
                last_index = lookup[last.campaign]
                stubs = promo_tuples[last_index + 1:]
                promoted_links.extend(stubs)

        if not (organic_fullnames or promoted_links):
            return None

        random.shuffle(organic_fullnames)
        organic_fullnames = organic_fullnames[:10]
        b = IDBuilder(organic_fullnames,
                      wrap=self.builder_wrapper,
                      keep_fn=organic.keep_fresh_links,
                      skip=True)
        organic_links = b.get_items()[0]

        has_subscribed = c.user.has_subscribed
        interestbar_prob = g.live_config['spotlight_interest_sub_p'
                                         if has_subscribed else
                                         'spotlight_interest_nosub_p']
        interestbar = InterestBar(has_subscribed)
        promotion_prob = 0.5 if c.user_is_loggedin else 1.

        s = SpotlightListing(organic_links=organic_links,
                             promoted_links=promoted_links,
                             interestbar=interestbar,
                             interestbar_prob=interestbar_prob,
                             promotion_prob=promotion_prob,
                             max_num = self.listing_obj.max_num,
                             max_score = self.listing_obj.max_score,
                             predetermined_winner=c.user_is_loggedin).listing()
        return s
开发者ID:dkuznetsov,项目名称:reddit,代码行数:82,代码来源:listingcontroller.py


示例8: spotlight

    def spotlight(self):
        if (self.requested_ad or
            not isinstance(c.site, DefaultSR) and c.user.pref_show_sponsors):

            link_ids = None

            if self.requested_ad:
                link = None
                try:
                    link = Link._by_fullname(self.requested_ad)
                except NotFound:
                    pass

                if not (link and link.promoted and
                        (c.user_is_sponsor or
                         c.user_is_loggedin and link.author_id == c.user._id)):
                    return self.abort404()

                # check if we can show the requested ad
                if promote.is_live_on_sr(link, c.site.name):
                    link_ids = [link._fullname]
                else:
                    return _("requested campaign not eligible for display")
            else:
                # no organic box on a hot page, then show a random promoted link
                link_ids = randomized_promotion_list(c.user, c.site)

            if link_ids:
                res = wrap_links(link_ids, wrapper=self.builder_wrapper,
                                 num=1, keep_fn=lambda x: x.fresh, skip=True)
                res.parent_name = "promoted"
                if res.things:
                    return res

        elif (isinstance(c.site, DefaultSR)
            and (not c.user_is_loggedin
                 or (c.user_is_loggedin and c.user.pref_organic))):

            # Spotlight shows rising links. If available, mix in subreddit
            # discovery links as well. (These don't count towards ad bids)
            spotlight_links = organic.organic_links(c.user)
            if hasattr(g, 'sr_discovery_links'):
                spotlight_links.extend(g.sr_discovery_links)
                random.shuffle(spotlight_links)
                spotlight_keep_fn = lambda l: promote.is_promo(l) or organic.keep_fresh_links(l)
                num_links = len(spotlight_links)
            else:
                spotlight_keep_fn = organic.keep_fresh_links
                num_links = organic.organic_length

            pos = organic_pos()

            if not spotlight_links:
                pos = 0
            elif pos != 0:
                pos = pos % len(spotlight_links)

            if c.user.pref_show_sponsors or not c.user.gold:
                spotlight_links, pos = promote.insert_promoted(spotlight_links, pos)

            # Need to do this again, because if there was a duplicate removed,
            # pos might be pointing outside the list.
            if not spotlight_links:
                pos = 0
            elif pos != 0:
                pos = pos % len(spotlight_links)

            if not spotlight_links:
                return None

            # get links in proximity to pos
            num_tl = len(spotlight_links)
            if num_tl <= 3:
                disp_links = spotlight_links
            else:
                left_side = max(-1, min(num_tl - 3, 8))
                disp_links = [spotlight_links[(i + pos) % num_tl]
                              for i in xrange(-2, left_side)]

            b = IDBuilder(disp_links,
                          wrap = self.builder_wrapper,
                          num = num_links,
                          keep_fn = spotlight_keep_fn,
                          skip = True)

            try:
                vislink = spotlight_links[pos]
            except IndexError:
                g.log.error("spotlight_links = %r" % spotlight_links)
                g.log.error("pos = %d" % pos)
                raise

            s = SpotlightListing(b, spotlight_links = spotlight_links,
                                 visible_link = vislink,
                                 max_num = self.listing_obj.max_num,
                                 max_score = self.listing_obj.max_score).listing()

            if len(s.things) > 0:
                # only pass through a listing if the links made it
                # through our builder
#.........这里部分代码省略.........
开发者ID:LDot,项目名称:reddit,代码行数:101,代码来源:listingcontroller.py


示例9: spotlight

    def spotlight(self):
        campaigns_by_link = {}
        if (self.requested_ad or
            not isinstance(c.site, DefaultSR) and c.user.pref_show_sponsors):

            link_ids = None

            if self.requested_ad:
                link = None
                try:
                    link = Link._by_fullname(self.requested_ad)
                except NotFound:
                    pass

                if not (link and link.promoted and
                        (c.user_is_sponsor or
                         c.user_is_loggedin and link.author_id == c.user._id)):
                    return self.abort404()

                # check if we can show the requested ad
                if promote.is_live_on_sr(link, c.site.name):
                    link_ids = [link._fullname]
                else:
                    return _("requested campaign not eligible for display")
            else:
                # no organic box on a hot page, then show a random promoted link
                promo_tuples = randomized_promotion_list(c.user, c.site)
                link_ids, camp_ids = zip(*promo_tuples) if promo_tuples else ([],[])

                # save campaign-to-link mapping so campaign can be added to 
                # link data later (for tracking.) Gotcha: assumes each link 
                # appears for only campaign
                campaigns_by_link = dict(promo_tuples)

            if link_ids:
                res = wrap_links(link_ids, wrapper=self.builder_wrapper,
                                 num=1, keep_fn=lambda x: x.fresh, skip=True)
                res.parent_name = "promoted"
                if res.things:
                    # store campaign id for tracking
                    for thing in res.things:
                        thing.campaign = campaigns_by_link.get(thing._fullname, None)
                    return res

        elif (isinstance(c.site, DefaultSR)
            and (not c.user_is_loggedin
                 or (c.user_is_loggedin and c.user.pref_organic))):

            spotlight_links = organic.organic_links(c.user)
            
            pos = organic_pos()

            if not spotlight_links:
                pos = 0
            elif pos != 0:
                pos = pos % len(spotlight_links)
            spotlight_keep_fn = organic.keep_fresh_links
            num_links = organic.organic_length

            # If prefs allow it, mix in promoted links and sr discovery content
            if c.user.pref_show_sponsors or not c.user.gold:
                if g.live_config['sr_discovery_links']:
                    spotlight_links.extend(g.live_config['sr_discovery_links'])
                    random.shuffle(spotlight_links)
                    spotlight_keep_fn = lambda l: promote.is_promo(l) or organic.keep_fresh_links(l)
                    num_links = len(spotlight_links)
                spotlight_links, pos, campaigns_by_link = promote.insert_promoted(spotlight_links,
                                                                                  pos) 

            # Need to do this again, because if there was a duplicate removed,
            # pos might be pointing outside the list.
            if not spotlight_links:
                pos = 0
            elif pos != 0:
                pos = pos % len(spotlight_links)

            if not spotlight_links:
                return None

            # get links in proximity to pos
            num_tl = len(spotlight_links)
            if num_tl <= 3:
                disp_links = spotlight_links
            else:
                left_side = max(-1, min(num_tl - 3, 8))
                disp_links = [spotlight_links[(i + pos) % num_tl]
                              for i in xrange(-2, left_side)]

            b = IDBuilder(disp_links,
                          wrap = self.builder_wrapper,
                          num = num_links,
                          keep_fn = spotlight_keep_fn,
                          skip = True)

            try:
                vislink = spotlight_links[pos]
            except IndexError:
                g.log.error("spotlight_links = %r" % spotlight_links)
                g.log.error("pos = %d" % pos)
                raise
#.........这里部分代码省略.........
开发者ID:jcald,项目名称:reddit,代码行数:101,代码来源:listingcontroller.py


示例10: spotlight

    def spotlight(self):
        """Build the Spotlight or a single promoted link.

        The frontpage gets a Spotlight box that contains promoted and organic
        links from the user's subscribed subreddits and promoted links targeted
        to the frontpage. Other subreddits get a single promoted link. In either
        case if the user has disabled ads promoted links will not be shown.

        The content of the Spotlight box is a bit tricky because a single
        version of the frontpage is cached and displayed to all logged out
        users. Because of the caching we must include many promoted links and
        select one to display on the client side. Otherwise, each logged out
        user would see the same promoted link and we would not get the desired
        distribution of promoted link views. Most of the promoted links are
        included as stubs to reduce the size of the page. When a promoted link
        stub is selected by the lottery the full link is fetched and displayed.

        There are only ~1000 cache resets per day so it is necessary to use
        a large subset of the eligible promoted links when choosing stubs for
        the Spotlight box. Using 100 stubs works great when there are fewer than
        100 possible promoted links and allows room for growth.

        """

        campaigns_by_link = {}
        if (self.requested_ad or
            not isinstance(c.site, DefaultSR) and c.user.pref_show_sponsors):

            link_ids = None

            if self.requested_ad:
                link = None
                try:
                    link = Link._by_fullname(self.requested_ad)
                except NotFound:
                    pass

                if not (link and link.promoted and
                        (c.user_is_sponsor or
                         c.user_is_loggedin and link.author_id == c.user._id)):
                    return self.abort404()

                # check if we can show the requested ad
                if promote.is_live_on_sr(link, c.site.name):
                    link_ids = [link._fullname]
                else:
                    return _("requested campaign not eligible for display")
            else:
                # no organic box on a hot page, then show a random promoted link
                promo_tuples = randomized_promotion_list(c.user, c.site)
                link_ids, camp_ids = zip(*promo_tuples) if promo_tuples else ([],[])

                # save campaign-to-link mapping so campaign can be added to 
                # link data later (for tracking.) Gotcha: assumes each link 
                # appears for only campaign
                campaigns_by_link = dict(promo_tuples)

            if link_ids:
                res = wrap_links(link_ids, wrapper=self.builder_wrapper,
                                 num=1, keep_fn=organic.keep_fresh_links,
                                 skip=True)
                res.parent_name = "promoted"
                if res.things:
                    # store campaign id for tracking
                    for thing in res.things:
                        thing.campaign = campaigns_by_link.get(thing._fullname, None)
                    return res

        elif (isinstance(c.site, DefaultSR)
            and (not c.user_is_loggedin
                 or (c.user_is_loggedin and c.user.pref_organic))):

            organic_fullnames = organic.organic_links(c.user)
            promoted_links = []

            # If prefs allow it, mix in promoted links and sr discovery content
            if c.user.pref_show_sponsors or not c.user.gold:
                if g.live_config['sr_discovery_links']:
                    organic_fullnames.extend(g.live_config['sr_discovery_links'])

                n_promoted = 100
                n_build = 10
                promo_tuples = promote.get_promoted_links(c.user, c.site,
                                                          n_promoted)
                promo_tuples = sorted(promo_tuples,
                                      key=lambda p: p.weight,
                                      reverse=True)
                promo_build = promo_tuples[:n_build]
                promo_stub = promo_tuples[n_build:]
                b = CampaignBuilder(promo_build,
                                    wrap=self.builder_wrapper,
                                    keep_fn=promote.is_promoted)
                promoted_links = b.get_items()[0]
                promoted_links.extend(promo_stub)

            if not (organic_fullnames or promoted_links):
                return None

            random.shuffle(organic_fullnames)
            organic_fullnames = organic_fullnames[:10]
#.........这里部分代码省略.........
开发者ID:cooiky,项目名称:reddit,代码行数:101,代码来源:listingcontroller.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python organic.update_pos函数代码示例发布时间:2022-05-26
下一篇:
Python normalized_hot.normalized_hot函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap