def POST_request_promo(self, srnames): if not srnames: return srnames = srnames.split('+') # request multiple ads in case some are hidden by the builder due # to the user's hides/preferences response = adzerk_request(srnames) if not response: g.stats.simple_event('adzerk.request.no_promo') return res_by_campaign = {r.campaign: r for r in response} tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response] builder = CampaignBuilder(tuples, wrap=default_thing_wrapper(), keep_fn=promote.is_promoted, num=1, skip=True) listing = LinkListing(builder, nextprev=False).listing() if listing.things: g.stats.simple_event('adzerk.request.valid_promo') w = listing.things[0] r = res_by_campaign[w.campaign] w.adserver_imp_pixel = r.imp_pixel w.adserver_click_url = r.click_url return spaceCompress(w.render()) else: g.stats.simple_event('adzerk.request.skip_promo')
def POST_request_promo(self, srnames, is_mobile_web, platform, loid, is_refresh): self.OPTIONS_request_promo() if not srnames: return # backwards compat if platform is None: platform = "mobile_web" if is_mobile_web else "desktop" srnames = srnames.split('+') # request multiple ads in case some are hidden by the builder due # to the user's hides/preferences response = adzerk_request(srnames, self.get_uid(loid), platform=platform) if not response: g.stats.simple_event('adzerk.request.no_promo') return # for adservers, adzerk returns markup so we pass it to the client if isinstance(response, AdserverResponse): g.stats.simple_event('adzerk.request.adserver') return responsive(response.body) res_by_campaign = {r.campaign: r for r in response} adserver_click_urls = {r.campaign: r.click_url for r in response} tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response] builder = CampaignBuilder(tuples, wrap=default_thing_wrapper(), keep_fn=promote.promo_keep_fn, num=1, skip=True) listing = LinkListing(builder, nextprev=False).listing() promote.add_trackers(listing.things, c.site, adserver_click_urls=adserver_click_urls) promote.update_served(listing.things) if listing.things: g.stats.simple_event('adzerk.request.valid_promo') if is_refresh: g.stats.simple_event('adzerk.request.auto_refresh') w = listing.things[0] r = res_by_campaign[w.campaign] up = UrlParser(r.imp_pixel) up.hostname = "pixel.redditmedia.com" w.adserver_imp_pixel = up.unparse() w.adserver_upvote_pixel = r.upvote_pixel w.adserver_downvote_pixel = r.downvote_pixel w.adserver_click_url = r.click_url w.num = "" return responsive(w.render(), space_compress=True) else: g.stats.simple_event('adzerk.request.skip_promo')
def GET_wiki_recent(self, num, after, reverse, count): revisions = WikiRevision.get_recent(c.site) builder = WikiRecentRevisionBuilder(revisions, num=num, count=count, reverse=reverse, after=after, wrap=default_thing_wrapper(), skip=not c.is_wiki_mod) listing = WikiRevisionListing(builder).listing() return WikiRecent(listing).render()
def GET_wiki_revisions(self, num, after, reverse, count, page): revisions = page.get_revisions() wikiuser = c.user if c.user_is_loggedin else None builder = WikiRevisionBuilder(revisions, user=wikiuser, sr=c.site, num=num, reverse=reverse, count=count, after=after, skip=not c.is_wiki_mod, wrap=default_thing_wrapper()) listing = WikiRevisionListing(builder).listing() return WikiRevisions(listing, page=page.name, may_revise=this_may_revise(page)).render()
def GET_wiki_recent(self, num, after, reverse, count): revisions = WikiRevision.get_recent(c.site) wikiuser = c.user if c.user_is_loggedin else None builder = WikiRecentRevisionBuilder(revisions, num=num, count=count, reverse=reverse, after=after, wrap=default_thing_wrapper(), skip=not c.is_wiki_mod, user=wikiuser, sr=c.site) listing = WikiRevisionListing(builder).listing() return WikiRecent(listing).render()
def GET_wiki_revisions(self, num, after, reverse, count, page): revisions = page.get_revisions() builder = WikiRevisionBuilder(revisions, num=num, reverse=reverse, count=count, after=after, skip=not c.is_wiki_mod, wrap=default_thing_wrapper()) listing = WikiRevisionListing(builder).listing() return WikiRevisions(listing).render()
def GET_wiki_revisions(self, num, after, reverse, count, page): revisions = page.get_revisions() builder = WikiRevisionBuilder( revisions, num=num, reverse=reverse, count=count, after=after, skip=not c.is_wiki_mod, wrap=default_thing_wrapper(), ) listing = WikiRevisionListing(builder).listing() return WikiRevisions(listing, page=page.name, may_revise=this_may_revise(page)).render()
def GET_wiki_recent(self, num, after, reverse, count): """Retrieve a list of recently changed wiki pages in this subreddit""" revisions = WikiRevision.get_recent(c.site) wikiuser = c.user if c.user_is_loggedin else None builder = WikiRecentRevisionBuilder(revisions, num=num, count=count, reverse=reverse, after=after, wrap=default_thing_wrapper(), skip=not c.is_wiki_mod, user=wikiuser, sr=c.site) listing = WikiRevisionListing(builder).listing() return WikiRecent(listing, sr_path=not c.site.is_homepage).render()
def POST_request_promo(self, srnames, is_mobile_web): self.OPTIONS_request_promo() if not srnames: return srnames = srnames.split('+') # request multiple ads in case some are hidden by the builder due # to the user's hides/preferences response = adzerk_request(srnames, mobile_web=is_mobile_web) if not response: g.stats.simple_event('adzerk.request.no_promo') return res_by_campaign = {r.campaign: r for r in response} tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response] builder = CampaignBuilder(tuples, wrap=default_thing_wrapper(), keep_fn=promote.promo_keep_fn, num=1, skip=True) listing = LinkListing(builder, nextprev=False).listing() promote.add_trackers(listing.things, c.site) if listing.things: g.stats.simple_event('adzerk.request.valid_promo') w = listing.things[0] r = res_by_campaign[w.campaign] up = UrlParser(r.imp_pixel) up.hostname = "pixel.redditmedia.com" w.adserver_imp_pixel = up.unparse() w.adserver_click_url = r.click_url w.num = "" return responsive(w.render(), space_compress=True) else: g.stats.simple_event('adzerk.request.skip_promo')
def POST_request_promo(self): if not (c.site and c.site.name in g.cpm_beta_srs): return super(AdzerkApiController, self).POST_request_promo() srids = promote.srids_with_live_promos(c.user, c.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) # request multiple ads in case some are hidden by the builder due # to the user's hides/preferences response = adzerk_request(srnames, num_placements=g.az_selfserve_num_request) if not response: return res_by_campaign = {r.campaign: r for r in response} tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response] builder = CampaignBuilder(tuples, wrap=default_thing_wrapper(), keep_fn=promote.is_promoted, num=1, skip=True) listing = LinkListing(builder, nextprev=False).listing() if listing.things: w = listing.things[0] r = res_by_campaign[w.campaign] w.adserver_imp_pixel = r.imp_pixel w.adserver_click_url = r.click_url return spaceCompress(w.render())
def POST_request_promo( self, site, srnames, is_mobile_web, platform, loid, is_refresh, placements, displayed_things, referrer, user_day, user_hour, adblock, ): self.OPTIONS_request_promo() if (errors.INVALID_SITE_PATH, "site") in c.errors: return abort(reddit_http_error(400, errors.INVALID_SITE_PATH)) displayed_list = displayed_things.split(',') if displayed_things else [] if site: keywords = promote.keywords_from_context( c.user, site, displayed_things=displayed_list, ) elif srnames: keywords = srnames.split('+') else: return properties = promote.properties_from_context( context=c, keywords=keywords, placement="sponsored_headline", displayed_things=displayed_list, exclude=(None if c.user_is_loggedin else ["age_hours"]), ) properties['user_day'] = user_day properties['user_hour'] = user_hour if adblock is not None: properties["adblock"] = adblock # backwards compat if platform is None: platform = "mobile_web" if is_mobile_web else "desktop" if not placements: placements = ["div0"] # request multiple ads in case some are hidden by the builder due # to the user's hides/preferences response = adzerk_request( keywords=keywords, properties=properties, user_id=self.get_uid(loid), placement_names=placements, platform=platform, is_refresh=is_refresh, referrer=referrer, timeout=int(g.live_config.get("ads_loading_timeout_ms", 1000) / 1000.), ) if not response: g.stats.simple_event('adzerk.request.no_promo') return # for blanks, adzerk returns markup so we pass it to the client if isinstance(response, BlankCreativeResponse): g.stats.simple_event('adzerk.request.blank') return responsive(response.body) res_by_campaign = {r.campaign: r for r in response} adserver_click_urls = {r.campaign: r.click_url for r in response} priorities = {r.campaign: r.priority for r in response} tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response] builder = CampaignBuilder(tuples, wrap=default_thing_wrapper(), keep_fn=promote.promo_keep_fn, num=1, skip=True) listing = LinkListing(builder, nextprev=False).listing() promote.add_trackers( listing.things, c.site, adserver_click_urls=adserver_click_urls, priorities=priorities) promote.update_served(listing.things) if listing.things: g.stats.simple_event('adzerk.request.valid_promo') if is_refresh: g.stats.simple_event('adzerk.request.auto_refresh') w = listing.things[0] r = res_by_campaign[w.campaign] up = UrlParser(r.imp_pixel) up.hostname = "pixel.redditmedia.com" w.adserver_imp_pixel = up.unparse() w.adserver_upvote_pixel = r.upvote_pixel w.adserver_downvote_pixel = r.downvote_pixel w.adserver_click_url = r.click_url w.ecpm = r.ecpm w.moat_query = r.moat_query w.num = "" return responsive(w.render(), space_compress=True) else: g.stats.simple_event('adzerk.request.skip_promo')
def POST_request_promo( self, site, srnames, is_mobile_web, platform, loid, is_refresh, displayed_things, referrer, ): self.OPTIONS_request_promo() if (errors.INVALID_SITE_PATH, "site") in c.errors: return abort(reddit_http_error(400, errors.INVALID_SITE_PATH)) displayed_list = displayed_things.split(',') if displayed_things else [] if site: keywords = promote.keywords_from_context( c.user, site, displayed_things=displayed_list, ) elif srnames: keywords = srnames.split('+') else: return properties = properties_from_context(c, site) # backwards compat if platform is None: platform = "mobile_web" if is_mobile_web else "desktop" # request multiple ads in case some are hidden by the builder due # to the user's hides/preferences response = adzerk_request( keywords=keywords, properties=properties, user_id=self.get_uid(loid), platform=platform, is_refresh=is_refresh, referrer=referrer, ) if not response: g.stats.simple_event('adzerk.request.no_promo') return # for adservers, adzerk returns markup so we pass it to the client if isinstance(response, AdserverResponse): g.stats.simple_event('adzerk.request.adserver') return responsive(response.body) res_by_campaign = {r.campaign: r for r in response} adserver_click_urls = {r.campaign: r.click_url for r in response} tuples = [promote.PromoTuple(r.link, 1., r.campaign) for r in response] builder = CampaignBuilder(tuples, wrap=default_thing_wrapper(), keep_fn=promote.promo_keep_fn, num=1, skip=True) listing = LinkListing(builder, nextprev=False).listing() promote.add_trackers(listing.things, c.site, adserver_click_urls=adserver_click_urls) promote.update_served(listing.things) if listing.things: g.stats.simple_event('adzerk.request.valid_promo') if is_refresh: g.stats.simple_event('adzerk.request.auto_refresh') w = listing.things[0] r = res_by_campaign[w.campaign] up = UrlParser(r.imp_pixel) up.hostname = "pixel.redditmedia.com" w.adserver_imp_pixel = up.unparse() w.adserver_upvote_pixel = r.upvote_pixel w.adserver_downvote_pixel = r.downvote_pixel w.adserver_click_url = r.click_url w.ecpm = r.ecpm w.moat_query = r.moat_query w.num = "" return responsive(w.render(), space_compress=True) else: g.stats.simple_event('adzerk.request.skip_promo')
def builder_wrapper(self, thing): builder_wrapper = default_thing_wrapper() w = builder_wrapper(thing) w.hide_after_seen = self.sort == "future_promos" return w