Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
def weight_schedule(by_sr):
    """
    Arguments:
      by_sr - a dict mapping subreddit names to lists of (Link, bid) tuples. 
        Usually this data struct would come from the output of get_scheduled
    Returns:
      a dict just like by_sr but with bids replaced by weights 
    """
    weight_dict = get_traffic_weights(by_sr.keys())
    weighted = {}
    for sr_name, t_tuples in by_sr.iteritems():
        weighted[sr_name] = []
        for l, weight, cid in t_tuples:
            weighted[sr_name].append(
                AdWeight(l._fullname, weight * weight_dict[sr_name], cid))
    return weighted
Ejemplo n.º 3
0
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))