def promote_link(link, campaign): if not link.over_18 and not link.over_18_override and any(sr.over_18 for sr in campaign.target.subreddits_slow): link.over_18 = True link._commit() if not is_promoted(link): update_promote_status(link, PROMOTE_STATUS.promoted) emailer.live_promo(link)
def promote_link(link, campaign): if (not link.over_18 and not link.over_18_override and any(sr.over_18 for sr in campaign.target.subreddits_slow)): link.over_18 = True link._commit() if not is_promoted(link): update_promote_status(link, PROMOTE_STATUS.promoted) emailer.live_promo(link)
def promote_link(link, campaign): if (not link.over_18 and campaign.sr_name and Subreddit._by_name(campaign.sr_name).over_18): link.over_18 = True link._commit() if not is_promoted(link): update_promote_status(link, PROMOTE_STATUS.promoted) emailer.live_promo(link)
def promote_link(link, campaign): if (not link.over_18 and not link.over_18_override and campaign.sr_name and Subreddit._by_name(campaign.sr_name).over_18): link.over_18 = True link._commit() if not is_promoted(link): update_promote_status(link, PROMOTE_STATUS.promoted) emailer.live_promo(link)
def promote(thing, batch = False): """ Given a promotion with pending status, set the status to promoted and move it into the promoted queue. """ if thing.promote_status == STATUS.pending: promotion_log(thing, "status update: live") PromoteDates.log_start(thing) thing.promoted_on = datetime.now(g.tz) thing.promote_status = STATUS.promoted thing._commit() emailer.live_promo(thing) if not batch: with g.make_lock(promoted_lock_key): promoted = get_promoted_direct() if thing._fullname not in promoted: promoted[thing._fullname] = auction_weight(thing) set_promoted(promoted)
def make_daily_promotions(offset=0, test=False): old_links = set([]) all_links, weighted = get_weighted_schedule(offset) # over18 check for sr, links in weighted.iteritems(): if sr: sr = Subreddit._by_name(sr) if sr.over_18: for l in Link._by_fullname([l[0] for l in links], return_dict=False): l.over_18 = True l._commit() x = get_live_promotions() if x: old_links, old_weights = x # links that need to be promoted new_links = all_links - old_links # links that have already been promoted old_links = old_links - all_links else: new_links = links links = Link._by_fullname(new_links.union(old_links), data=True, return_dict=True) for l in old_links: if is_promoted(links[l]): if test: print "unpromote", l else: # update the query queue set_status(links[l], STATUS.finished, onchange=lambda: emailer.finished_promo(links[l])) for l in new_links: if is_accepted(links[l]): if test: print "promote2", l else: # update the query queue set_status(links[l], STATUS.promoted, onchange=lambda: emailer.live_promo(links[l])) # convert the weighted dict to use sr_ids which are more useful srs = {"": ""} for srname in weighted.keys(): if srname: srs[srname] = Subreddit._by_name(srname)._id weighted = dict((srs[k], v) for k, v in weighted.iteritems()) if not test: set_live_promotions((all_links, weighted)) else: print(all_links, weighted)
def make_daily_promotions(offset = 0, test = False): old_links = set([]) all_links, weighted = get_weighted_schedule(offset) # over18 check for sr, links in weighted.iteritems(): if sr: sr = Subreddit._by_name(sr) if sr.over_18: for l in Link._by_fullname([l[0] for l in links], return_dict = False): l.over_18 = True l._commit() x = get_live_promotions() if x: old_links, old_weights = x # links that need to be promoted new_links = all_links - old_links # links that have already been promoted old_links = old_links - all_links else: new_links = links links = Link._by_fullname(new_links.union(old_links), data = True, return_dict = True) for l in old_links: if is_promoted(links[l]): if test: print "unpromote", l else: # update the query queue set_status(links[l], STATUS.finished, onchange = lambda: emailer.finished_promo(links[l])) for l in new_links: if is_accepted(links[l]): if test: print "promote2", l else: # update the query queue set_status(links[l], STATUS.promoted, onchange = lambda: emailer.live_promo(links[l])) # convert the weighted dict to use sr_ids which are more useful srs = {"":""} for srname in weighted.keys(): if srname: srs[srname] = Subreddit._by_name(srname)._id weighted = dict((srs[k], v) for k, v in weighted.iteritems()) if not test: set_live_promotions((all_links, weighted)) else: print (all_links, weighted)
def make_daily_promotions(offset=0, test=False): """ Arguments: offset - number of days after today to get the schedule for test - if True, new schedule will be generated but not launched Raises Exception with list of campaigns that had errors if there were any """ by_srname, links, error_campaigns = get_scheduled(offset) all_links = set([l._fullname for l in links]) srs = Subreddit._by_name(by_srname.keys()) # over18 check for srname, adweights in by_srname.iteritems(): if srname: sr = srs[srname] if sr.over_18: sr_links = Link._by_fullname([a.link for a in adweights], return_dict=False) for l in sr_links: l.over_18 = True if not test: l._commit() old_ads = get_live_promotions([LiveAdWeights.ALL_ADS]) old_links = set(x.link for x in old_ads[LiveAdWeights.ALL_ADS]) # links that need to be promoted new_links = all_links - old_links # links that have already been promoted old_links = old_links - all_links links = Link._by_fullname(new_links.union(old_links), data=True, return_dict=True) for l in old_links: if is_promoted(links[l]): if test: print "unpromote", l else: # update the query queue set_promote_status(links[l], PROMOTE_STATUS.finished) emailer.finished_promo(links[l]) for l in new_links: if is_accepted(links[l]): if test: print "promote2", l else: # update the query queue set_promote_status(links[l], PROMOTE_STATUS.promoted) emailer.live_promo(links[l]) # convert the weighted dict to use sr_ids which are more useful by_srid = { srs[srname]._id: adweights for srname, adweights in by_srname.iteritems() if srname != '' } if '' in by_srname: by_srid[''] = by_srname[''] if not test: set_live_promotions(by_srid) _mark_promos_updated() else: print by_srid # after launching as many campaigns as possible, raise an exception to # report any error campaigns. (useful for triggering alerts in irc) if error_campaigns: raise Exception("Some scheduled campaigns could not be added to daily " "promotions: %r" % error_campaigns)
def make_daily_promotions(offset=0, test=False): """ Arguments: offset - number of days after today to get the schedule for test - if True, new schedule will be generated but not launched Raises Exception with list of campaigns that had errors if there were any """ scheduled_adweights, error_campaigns = get_scheduled(offset) current_adweights_byid = get_live_promotions([LiveAdWeights.ALL_ADS]) current_adweights = current_adweights_byid[LiveAdWeights.ALL_ADS] link_names = [aw.link for aw in itertools.chain(scheduled_adweights, current_adweights)] links = Link._by_fullname(link_names, data=True) camp_names = [aw.campaign for aw in itertools.chain(scheduled_adweights, current_adweights)] campaigns = PromoCampaign._by_fullname(camp_names, data=True) srs = Subreddit._by_name([camp.sr_name for camp in campaigns.itervalues() if camp.sr_name]) expired_links = ({aw.link for aw in current_adweights} - {aw.link for aw in scheduled_adweights}) for link_name in expired_links: link = links[link_name] if is_promoted(link): if test: print "unpromote", link_name else: # update the query queue set_promote_status(link, PROMOTE_STATUS.finished) emailer.finished_promo(link) by_srid = defaultdict(list) for adweight in scheduled_adweights: link = links[adweight.link] campaign = campaigns[adweight.campaign] if campaign.sr_name: sr = srs[campaign.sr_name] sr_id = sr._id sr_over_18 = sr.over_18 else: sr_id = '' sr_over_18 = False if sr_over_18: if test: print "over18", link._fullname else: link.over_18 = True link._commit() if is_accepted(link) and not is_promoted(link): if test: print "promote2", link._fullname else: # update the query queue set_promote_status(link, PROMOTE_STATUS.promoted) emailer.live_promo(link) by_srid[sr_id].append(adweight) if not test: set_live_promotions(by_srid) _mark_promos_updated() else: print by_srid finalize_completed_campaigns(daysago=offset+1) hooks.get_hook('promote.make_daily_promotions').call(offset=offset) # after launching as many campaigns as possible, raise an exception to # report any error campaigns. (useful for triggering alerts in irc) if error_campaigns: raise Exception("Some scheduled campaigns could not be added to daily " "promotions: %r" % error_campaigns)
def make_daily_promotions(offset = 0, test = False): """ Arguments: offset - number of days after today to get the schedule for test - if True, new schedule will be generated but not launched Raises Exception with list of campaigns that had errors if there were any """ schedule = get_scheduled(offset) all_links = set([l._fullname for l in schedule['links']]) error_campaigns = schedule['error_campaigns'] weighted = weight_schedule(schedule['by_sr']) # over18 check for sr, links in weighted.iteritems(): if sr: sr = Subreddit._by_name(sr) if sr.over_18: for l in Link._by_fullname([l[0] for l in links], return_dict = False): l.over_18 = True if not test: l._commit() old_links = get_live_promotions([SponsorBoxWeightings.ALL_ADS_ID])[0] # links that need to be promoted new_links = all_links - old_links # links that have already been promoted old_links = old_links - all_links links = Link._by_fullname(new_links.union(old_links), data = True, return_dict = True) for l in old_links: if is_promoted(links[l]): if test: print "unpromote", l else: # update the query queue set_promote_status(links[l], PROMOTE_STATUS.finished) emailer.finished_promo(links[l]) for l in new_links: if is_accepted(links[l]): if test: print "promote2", l else: # update the query queue set_promote_status(links[l], PROMOTE_STATUS.promoted) emailer.live_promo(links[l]) # convert the weighted dict to use sr_ids which are more useful srs = {"":""} for srname in weighted.keys(): if srname: srs[srname] = Subreddit._by_name(srname)._id weighted = dict((srs[k], v) for k, v in weighted.iteritems()) if not test: set_live_promotions(all_links, weighted) _mark_promos_updated() else: print (all_links, weighted) # after launching as many campaigns as possible, raise an exception to # report any error campaigns. (useful for triggering alerts in irc) if error_campaigns: raise Exception("Some scheduled campaigns could not be added to daily " "promotions: %r" % error_campaigns)
def make_daily_promotions(offset=0, test=False): """ Arguments: offset - number of days after today to get the schedule for test - if True, new schedule will be generated but not launched Raises Exception with list of campaigns that had errors if there were any """ by_srname, links, error_campaigns = get_scheduled(offset) all_links = set([l._fullname for l in links]) srs = Subreddit._by_name(by_srname.keys()) # over18 check for srname, adweights in by_srname.iteritems(): if srname: sr = srs[srname] if sr.over_18: sr_links = Link._by_fullname([a.link for a in adweights], return_dict=False) for l in sr_links: l.over_18 = True if not test: l._commit() old_ads = get_live_promotions([LiveAdWeights.ALL_ADS]) old_links = set(x.link for x in old_ads[LiveAdWeights.ALL_ADS]) # links that need to be promoted new_links = all_links - old_links # links that have already been promoted old_links = old_links - all_links links = Link._by_fullname(new_links.union(old_links), data=True, return_dict=True) for l in old_links: if is_promoted(links[l]): if test: print "unpromote", l else: # update the query queue set_promote_status(links[l], PROMOTE_STATUS.finished) emailer.finished_promo(links[l]) for l in new_links: if is_accepted(links[l]): if test: print "promote2", l else: # update the query queue set_promote_status(links[l], PROMOTE_STATUS.promoted) emailer.live_promo(links[l]) # convert the weighted dict to use sr_ids which are more useful by_srid = {srs[srname]._id: adweights for srname, adweights in by_srname.iteritems() if srname != ''} if '' in by_srname: by_srid[''] = by_srname[''] if not test: set_live_promotions(by_srid) _mark_promos_updated() else: print by_srid # after launching as many campaigns as possible, raise an exception to # report any error campaigns. (useful for triggering alerts in irc) if error_campaigns: raise Exception("Some scheduled campaigns could not be added to daily " "promotions: %r" % error_campaigns)
def make_daily_promotions(offset=0, test=False): ''' Arguments: offset - number of days after today to get the schedule for test - if True, new schedule will be generated but not launched Raises Exception with list of campaigns that had errors if there were any ''' old_links = set([]) schedule = get_scheduled(offset) all_links = set([l._fullname for l in schedule['links']]) error_campaigns = schedule['error_campaigns'] weighted = weight_schedule(schedule['by_sr']) # over18 check for sr, links in weighted.iteritems(): if sr: sr = Subreddit._by_name(sr) if sr.over_18: for l in Link._by_fullname([l[0] for l in links], return_dict=False): l.over_18 = True if not test: l._commit() x = get_live_promotions() if x: old_links, old_weights = x # links that need to be promoted new_links = all_links - old_links # links that have already been promoted old_links = old_links - all_links else: new_links = links links = Link._by_fullname(new_links.union(old_links), data=True, return_dict=True) for l in old_links: if is_promoted(links[l]): if test: print "unpromote", l else: # update the query queue set_status(links[l], STATUS.finished, onchange=lambda: emailer.finished_promo(links[l])) for l in new_links: if is_accepted(links[l]): if test: print "promote2", l else: # update the query queue set_status(links[l], STATUS.promoted, onchange=lambda: emailer.live_promo(links[l])) # convert the weighted dict to use sr_ids which are more useful srs = {"": ""} for srname in weighted.keys(): if srname: srs[srname] = Subreddit._by_name(srname)._id weighted = dict((srs[k], v) for k, v in weighted.iteritems()) if not test: set_live_promotions((all_links, weighted)) else: print(all_links, weighted) # after launching as many campaigns as possible, raise an exception to # report any error campaigns. (useful for triggering alerts in irc) if error_campaigns: raise Exception("Some scheduled campaigns could not be added to daily " "promotions: %r" % error_campaigns)