def get_scheduled(offset=0): """ Arguments: offset - number of days after today you want the schedule for Returns: {'by_sr': dict, 'links':set(), 'error_campaigns':[]} -by_sr maps sr names to lists of (Link, bid, campaign_fullname) tuples -links is the set of promoted Link objects used in the schedule -error_campaigns is a list of (campaign_id, error_msg) tuples if any exceptions were raised or an empty list if there were none Note: campaigns in error_campaigns will not be included in by_sr """ by_sr = {} error_campaigns = [] links = set() for l, campaign, weight in accepted_campaigns(offset=offset): try: if authorize.is_charged_transaction(campaign.trans_id, campaign._id): adweight = AdWeight(l._fullname, weight, campaign._fullname) by_sr.setdefault(campaign.sr_name, []).append(adweight) links.add(l) except Exception, e: # could happen if campaign things have corrupt data error_campaigns.append((campaign._id, e))
def charge_pending(offset=1): for l, camp, weight in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) try: if authorize.is_charged_transaction(camp.trans_id, camp._id): # already charged continue charge_succeeded = authorize.charge_transaction(user, camp.trans_id, camp._id) if not charge_succeeded: continue hooks.get_hook('promote.new_charge').call(link=l, campaign=camp) if is_promoted(l): emailer.queue_promo(l, camp.bid, camp.trans_id) else: set_promote_status(l, PROMOTE_STATUS.pending) emailer.queue_promo(l, camp.bid, camp.trans_id) text = ('auth charge for campaign %s, trans_id: %d' % (camp._id, camp.trans_id)) PromotionLog.add(l, text) except: print "Error on %s, campaign %s" % (l, camp._id)
def get_scheduled(offset=0): by_sr = {} for l, index, camp in accepted_campaigns(offset=offset): sd, ed, bid, sr, trans_id = camp if authorize.is_charged_transaction(trans_id, index): by_sr.setdefault(sr, []).append((l, bid)) return by_sr
def charge_pending(offset=1): for l, camp, weight in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) try: if authorize.is_charged_transaction(camp.trans_id, camp._id): # already charged continue charge_succeeded = authorize.charge_transaction(user, camp.trans_id, camp._id) if not charge_succeeded: continue hooks.get_hook('promote.new_charge').call(link=l, campaign=camp) if is_promoted(l): emailer.queue_promo(l, camp.bid, camp.trans_id) else: set_promote_status(l, PROMOTE_STATUS.pending) emailer.queue_promo(l, camp.bid, camp.trans_id) text = ('auth charge for campaign %s, trans_id: %d' % (camp._id, camp.trans_id)) PromotionLog.add(l, text) except: print "Error on %s, campaign %s" % (l, camp._id)
def scheduled_campaigns_by_link(l, date=None): # A promotion/campaign is scheduled/live if it's in # PromotionWeights.get_campaigns(now) and # authorize.is_charged_transaction() date = date or promo_datetime_now() if not is_accepted(l): return [] if not l.campaigns: return [] scheduled = PromotionWeights.get_campaigns(date) campaigns = [c.promo_idx for c in scheduled if c.thing_name == l._fullname] # Check authorize accepted = [] for index in campaigns: if not index in l.campaigns: continue sd, ed, bid, sr, trans_id = l.campaigns[index] if authorize.is_charged_transaction(trans_id, index): accepted.append(index) return accepted
def scheduled_campaigns_by_link(l, date=None): # A promotion/campaign is scheduled/live if it's in # PromotionWeights.get_campaigns(now) and # authorize.is_charged_transaction() date = date or promo_datetime_now() if not is_accepted(l): return [] scheduled = PromotionWeights.get_campaigns(date) campaigns = [c.promo_idx for c in scheduled if c.thing_name == l._fullname] # Check authorize accepted = [] for campaign_id in campaigns: try: campaign = PromoCampaign._byID(campaign_id, data=True) if authorize.is_charged_transaction(campaign.trans_id, campaign_id): accepted.append(campaign_id) except NotFound: g.log.error("PromoCampaign %d scheduled to run on %s not found." % (campaign_id, date.strftime("%Y-%m-%d"))) return accepted
def scheduled_campaigns_by_link(l, date=None): # A promotion/campaign is scheduled/live if it's in # PromotionWeights.get_campaigns(now) and # authorize.is_charged_transaction() date = date or promo_datetime_now() if not is_accepted(l): return [] scheduled = PromotionWeights.get_campaigns(date) campaigns = [c.promo_idx for c in scheduled if c.thing_name == l._fullname] # Check authorize accepted = [] for campaign_id in campaigns: try: campaign = PromoCampaign._byID(campaign_id, data=True) if authorize.is_charged_transaction(campaign.trans_id, campaign_id): accepted.append(campaign_id) except NotFound: g.log.error("PromoCampaign %d scheduled to run on %s not found." % (campaign_id, date.strftime("%Y-%m-%d"))) return accepted
def make_adzerk_promotions(offset=0): # make sure is_charged_transaction and is_accepted are the only criteria # for a campaign going live! for link, campaign, weight in promote.accepted_campaigns(offset=offset): if (authorize.is_charged_transaction(campaign.trans_id, campaign._id) and promote.is_accepted(link)): update_adzerk(link, campaign)
def make_adzerk_promotions(offset=0): # make sure is_charged_transaction and is_accepted are the only criteria # for a campaign going live! for link, campaign, weight in promote.accepted_campaigns(offset=offset): if (authorize.is_charged_transaction(campaign.trans_id, campaign._id) and promote.is_accepted(link)): update_adzerk(link, campaign)
def get_scheduled(offset=0): by_sr = {} failed = [] for l, campaign, weight in accepted_campaigns(offset=offset): try: if authorize.is_charged_transaction(campaign.trans_id, campaign._id): by_sr.setdefault(campaign.sr_name, []).append((l, weight)) except Exception, e: # could happen if campaign things have corrupt data failed.append((campaign._id, e))
def make_adzerk_promotions(offset=0): # campaign goes live if is_charged_transaction and is_accepted for link, campaign, weight in promote.accepted_campaigns(offset=offset): if (authorize.is_charged_transaction(campaign.trans_id, campaign._id) and promote.is_accepted(link)): if is_overdelivered(campaign): deactivate_campaign(link, campaign) else: update_adzerk(link, campaign)
def _charge(l, camp, indx, weight): user = Account._byID(l.author_id) sd, ed, bid, sr, trans_id = camp try: if (not authorize.is_charged_transaction(trans_id, indx) and authorize.charge_transaction(user, trans_id, indx)): # update the query queue if is_promoted(l): emailer.queue_promo(l, bid, trans_id) else: set_status(l, STATUS.pending, onchange = lambda: emailer.queue_promo(l, bid, trans_id) ) promotion_log(l, "auth charge for campaign %s, trans_id: %d" % (indx, trans_id), True) except: print "Error on %s, campaign %s" % (l, indx)
def _charge(l, camp, indx, weight): user = Account._byID(l.author_id) sd, ed, bid, sr, trans_id = camp try: if (not authorize.is_charged_transaction(trans_id, indx) and authorize.charge_transaction(user, trans_id, indx)): # TODO: probably not absolutely necessary promotion_log(l, "status update: pending") # update the query queue if is_promoted(l): emailer.queue_promo(l, bid, trans_id) else: set_status(l, STATUS.pending, onchange = lambda: emailer.queue_promo(l, bid, trans_id) ) except: print "Error on %s, campaign %s" % (l, indx)
def charge_pending(offset=1): for l, camp, weight in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) try: if authorize.is_charged_transaction(camp.trans_id, camp._id) or not authorize.charge_transaction( user, camp.trans_id, camp._id ): continue if is_promoted(l): emailer.queue_promo(l, camp.bid, camp.trans_id) else: set_status(l, STATUS.pending, onchange=lambda: emailer.queue_promo(l, camp.bid, camp.trans_id)) promotion_log(l, "auth charge for campaign %s, trans_id: %d" % (camp._id, camp.trans_id), commit=True) except: print "Error on %s, campaign %s" % (l, camp._id)
def charge_pending(offset=1): for l, index, camp in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) sd, ed, bid, sr, trans_id = camp try: if (authorize.is_charged_transaction(trans_id, index) or not authorize.charge_transaction(user, trans_id, index)): continue if is_promoted(l): emailer.queue_promo(l, bid, trans_id) else: set_status(l, STATUS.pending, onchange=lambda: emailer.queue_promo(l, bid, trans_id)) promotion_log(l, "auth charge for campaign %s, trans_id: %d" % (index, trans_id), True) except: print "Error on %s, campaign %s" % (l, index)
def _charge(l, camp, indx, weight): user = Account._byID(l.author_id) sd, ed, bid, sr, trans_id = camp try: if (not authorize.is_charged_transaction(trans_id, indx) and authorize.charge_transaction(user, trans_id, indx)): # TODO: probably not absolutely necessary promotion_log(l, "status update: pending") # update the query queue if is_promoted(l): emailer.queue_promo(l, bid, trans_id) else: set_status( l, STATUS.pending, onchange=lambda: emailer.queue_promo(l, bid, trans_id)) except: print "Error on %s, campaign %s" % (l, indx)
def charge_pending(offset=1): for l, camp, weight in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) try: if (authorize.is_charged_transaction(camp.trans_id, camp._id) or not authorize.charge_transaction(user, camp.trans_id, camp._id)): continue if is_promoted(l): emailer.queue_promo(l, camp.bid, camp.trans_id) else: set_promote_status(l, PROMOTE_STATUS.pending) emailer.queue_promo(l, camp.bid, camp.trans_id) text = ('auth charge for campaign %s, trans_id: %d' % (camp._id, camp.trans_id)) PromotionLog.add(l, text) except: print "Error on %s, campaign %s" % (l, camp._id)
def charge_pending(offset=1): for l, camp, weight in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) try: if (authorize.is_charged_transaction(camp.trans_id, camp._id) or not authorize.charge_transaction(user, camp.trans_id, camp._id)): continue if is_promoted(l): emailer.queue_promo(l, camp.bid, camp.trans_id) else: set_promote_status(l, PROMOTE_STATUS.pending) emailer.queue_promo(l, camp.bid, camp.trans_id) text = ('auth charge for campaign %s, trans_id: %d' % (camp._id, camp.trans_id)) PromotionLog.add(l, text) except: print "Error on %s, campaign %s" % (l, camp._id)
def _charge(l, camp, indx, weight): user = Account._byID(l.author_id) sd, ed, bid, sr, trans_id = camp try: if (not authorize.is_charged_transaction(trans_id, indx) and authorize.charge_transaction(user, trans_id, indx)): # update the query queue if is_promoted(l): emailer.queue_promo(l, bid, trans_id) else: set_status( l, STATUS.pending, onchange=lambda: emailer.queue_promo(l, bid, trans_id)) promotion_log( l, "auth charge for campaign %s, trans_id: %d" % (indx, trans_id), True) except: print "Error on %s, campaign %s" % (l, indx)
def get_scheduled(offset=0): """ Arguments: offset - number of days after today you want the schedule for Returns: {'adweights':[], 'error_campaigns':[]} -adweights is a list of Adweight objects used in the schedule -error_campaigns is a list of (campaign_id, error_msg) tuples if any exceptions were raised or an empty list if there were none Note: campaigns in error_campaigns will not be included in by_sr """ adweights = [] error_campaigns = [] for l, campaign, weight in accepted_campaigns(offset=offset): try: if authorize.is_charged_transaction(campaign.trans_id, campaign._id): adweight = AdWeight(l._fullname, weight, campaign._fullname) adweights.append(adweight) except Exception, e: # could happen if campaign things have corrupt data error_campaigns.append((campaign._id, e))
def get_scheduled(offset=0): """ Arguments: offset - number of days after today you want the schedule for Returns: {'adweights':[], 'error_campaigns':[]} -adweights is a list of Adweight objects used in the schedule -error_campaigns is a list of (campaign_id, error_msg) tuples if any exceptions were raised or an empty list if there were none Note: campaigns in error_campaigns will not be included in by_sr """ adweights = [] error_campaigns = [] for l, campaign, weight in accepted_campaigns(offset=offset): try: if authorize.is_charged_transaction(campaign.trans_id, campaign._id): adweight = AdWeight(l._fullname, weight, campaign._fullname) adweights.append(adweight) except Exception, e: # could happen if campaign things have corrupt data error_campaigns.append((campaign._id, e))
def charge_pending(offset=1): for l, camp, weight in accepted_campaigns(offset=offset): user = Account._byID(l.author_id) try: if (authorize.is_charged_transaction(camp.trans_id, camp._id) or not authorize.charge_transaction( user, camp.trans_id, camp._id)): continue if is_promoted(l): emailer.queue_promo(l, camp.bid, camp.trans_id) else: set_status(l, STATUS.pending, onchange=lambda: emailer.queue_promo( l, camp.bid, camp.trans_id)) promotion_log(l, "auth charge for campaign %s, trans_id: %d" % (camp._id, camp.trans_id), commit=True) except: print "Error on %s, campaign %s" % (l, camp._id)
def get_scheduled(offset=0): """ Arguments: offset - number of days after today you want the schedule for Returns: {'by_sr': dict, 'links':set(), 'error_campaigns':[]} -by_sr maps sr names to lists of (Link, bid) tuples -links is the set of promoted Link objects used in the schedule -error_campaigns is a list of (campaign_id, error_msg) tuples if any exceptions were raised or an empty list if there were none Note: campaigns in error_campaigns will not be included in by_sr """ by_sr = {} error_campaigns = [] links = set() for l, campaign, weight in accepted_campaigns(offset=offset): try: if authorize.is_charged_transaction(campaign.trans_id, campaign._id): by_sr.setdefault(campaign.sr_name, []).append((l, weight)) links.add(l) except Exception, e: # could happen if campaign things have corrupt data error_campaigns.append((campaign._id, e))
def get_scheduled(offset=0): by_sr = {} for l, campaign, weight in accepted_campaigns(offset=offset): if authorize.is_charged_transaction(campaign.trans_id, campaign._id): by_sr.setdefault(campaign.sr_name, []).append((l, weight)) return by_sr
def make_adzerk_promotions(offset=0): # campaign goes live if is_charged_transaction and is_accepted for link, campaign, weight in promote.accepted_campaigns(offset=offset): if (authorize.is_charged_transaction(campaign.trans_id, campaign._id) and promote.is_accepted(link)): update_adzerk(link, campaign)
def charged_or_not_needed(campaign): # True if a campaign has a charged transaction or doesn't need one charged = authorize.is_charged_transaction(campaign.trans_id, campaign._id) needs_charge = campaign.priority.cpm return charged or not needs_charge
def charged_or_not_needed(campaign): # True if a campaign has a charged transaction or doesn't need one charged = authorize.is_charged_transaction(campaign.trans_id, campaign._id) needs_charge = campaign.priority.cpm return charged or not needs_charge
def _promote(l, camp, indx, weight): sd, ed, bid, sr, trans_id = camp if authorize.is_charged_transaction(trans_id, indx): by_sr.setdefault(sr, []).append((l, weight))
def _promote(l, camp, indx, weight): sd, ed, bid, sr, trans_id = camp if authorize.is_charged_transaction(trans_id, indx): by_sr.setdefault(sr, []).append((l, weight))