本文整理汇总了Python中r2.lib.emailer.finished_promo函数的典型用法代码示例。如果您正苦于以下问题:Python finished_promo函数的具体用法?Python finished_promo怎么用?Python finished_promo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了finished_promo函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: unpromote
def unpromote(thing, batch = False, status = STATUS.finished):
"""
unpromote a link with provided status, removing it from the
current promotional queue.
"""
if status == STATUS.finished:
PromoteDates.log_end(thing)
emailer.finished_promo(thing)
thing.unpromoted_on = datetime.now(g.tz)
promotion_log(thing, "status update: finished")
thing.promote_status = status
thing._commit()
if not batch:
with g.make_lock(promoted_lock_key):
promoted = get_promoted_direct()
if thing._fullname in promoted:
del promoted[thing._fullname]
set_promoted(promoted)
开发者ID:kevinrose,项目名称:diggit,代码行数:18,代码来源:promote.py
示例2: make_daily_promotions
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)
开发者ID:JediWatchman,项目名称:reddit,代码行数:53,代码来源:promote.py
示例3: make_daily_promotions
def make_daily_promotions():
# charge campaigns so they can go live
charge_pending(offset=0)
charge_pending(offset=1)
# promote links and record ids of promoted links
link_ids = set()
for campaign, link in get_scheduled_promos(offset=0):
link_ids.add(link._id)
promote_link(link, campaign)
# expire finished links
q = Link._query(Link.c.promote_status == PROMOTE_STATUS.promoted, data=True)
q = q._filter(not_(Link.c._id.in_(link_ids)))
for link in q:
update_promote_status(link, PROMOTE_STATUS.finished)
emailer.finished_promo(link)
# update subreddits with promos
all_live_promo_srnames(_update=True)
_mark_promos_updated()
finalize_completed_campaigns(daysago=1)
hooks.get_hook('promote.make_daily_promotions').call(offset=0)
开发者ID:APerson241,项目名称:reddit,代码行数:24,代码来源:promote.py
示例4: make_daily_promotions
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)
开发者ID:AD42,项目名称:reddit,代码行数:77,代码来源:promote.py
示例5: make_daily_promotions
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)
开发者ID:vinnydiehl,项目名称:reddit,代码行数:68,代码来源:promote.py
示例6: make_daily_promotions
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)
开发者ID:caseypatrickdriscoll,项目名称:reddit,代码行数:70,代码来源:promote.py
注:本文中的r2.lib.emailer.finished_promo函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论