本文整理汇总了Python中r2.models.keyvalue.NamedGlobals类的典型用法代码示例。如果您正苦于以下问题:Python NamedGlobals类的具体用法?Python NamedGlobals怎么用?Python NamedGlobals使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NamedGlobals类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_stats
def update_stats(config):
today = datetime.date.today()
yesterday_start = (today - datetime.timedelta(days=2))
yesterday_end = (today - datetime.timedelta(days=1))
last_month_end = (today.replace(day=1) - datetime.timedelta(days=1))
last_month_start = last_month_end.replace(day=1)
ranges = {
'yesterday': (yesterday_start, yesterday_end),
'last_month': (last_month_start, last_month_end),
}
stats = {"timestamp": int(time.time())}
def run_stats(f):
start_time = time.time()
stats.update(f(config, ranges))
end_time = time.time()
print >> sys.stderr, '%s took %0.2f seconds.' % (f.__name__, end_time - start_time)
print >> sys.stderr, 'recalculating reddit stats...'
run_stats(subreddit_stats)
run_stats(vote_stats)
run_stats(traffic_stats)
run_stats(ga_stats)
print >> sys.stderr, 'finished:', stats
NamedGlobals.set('about_reddit_stats', stats)
示例2: update_trending_subreddits
def update_trending_subreddits():
try:
trending_sr = Subreddit._by_name(g.config['trending_sr'])
except NotFound:
g.log.info("Unknown trending subreddit %r or trending_sr config "
"not set. Not updating.", g.config['trending_sr'])
return
iq = iter(trending_sr.get_links('new', 'all'))
link = Thing._by_fullname(next(iq), data=True)
subreddit_names = _SUBREDDIT_RE.findall(link.title)
trending_data = {
'subreddit_names': subreddit_names,
'permalink': link.make_permalink(trending_sr),
'link_id': link._id,
}
NamedGlobals.set(TRENDING_SUBREDDITS_KEY, trending_data)
g.log.debug("Trending subreddit data set to %r", trending_data)
示例3: has_timer_expired
def has_timer_expired():
# note: this only checks if the timer has been marked as expired, it doesn't
# actually check its value (that's done in check_timer)
key = _EXPIRED_KEY()
val = g.thebuttoncache.get(key)
if val is None:
try:
val = NamedGlobals.get(key)
except NotFoundException:
# has never been set, set the key
val = False
NamedGlobals.set(key, val)
# update the cache
g.thebuttoncache.set(key, val)
if val:
return _deserialize_datetime(val)
return val
示例4: GET_index
def GET_index(self):
quote = self._get_quote()
images = self._get_images()
stats = NamedGlobals.get("about_reddit_stats", None)
content = About(
quote=quote,
images=images,
stats=stats,
events=g.plugins["about"].timeline_data,
sites=g.plugins["about"].sites_data,
)
return AboutPage("about-main", _("we power awesome communities."), _("about reddit"), content).render()
示例5: update_trending_subreddits
def update_trending_subreddits():
try:
trending_sr = Subreddit._by_name(g.config['trending_sr'])
except NotFound:
g.log.info("Unknown trending subreddit %r or trending_sr config "
"not set. Not updating.", g.config['trending_sr'])
return
link = _get_newest_link(trending_sr)
if not link:
g.log.info("Unable to find active link in subreddit %r. Not updating.",
g.config['trending_sr'])
return
subreddit_names = _SUBREDDIT_RE.findall(link.title)
trending_data = {
'subreddit_names': subreddit_names,
'permalink': link.make_permalink(trending_sr),
'link_id': link._id,
}
NamedGlobals.set(TRENDING_SUBREDDITS_KEY, trending_data)
g.log.debug("Trending subreddit data set to %r", trending_data)
示例6: get_current_press
def get_current_press():
key = _CURRENT_PRESS_KEY()
val = g.thebuttoncache.get(key)
if val is None:
try:
val = NamedGlobals.get(key)
except NotFoundException:
val = NONE
g.thebuttoncache.set(key, val)
if val == NONE:
return None
elif val:
return _deserialize_datetime(val)
示例7: update_stats
def update_stats(config):
today = datetime.date.today()
yesterday_start = today - datetime.timedelta(days=2)
yesterday_end = today - datetime.timedelta(days=1)
last_month_end = today.replace(day=1) - datetime.timedelta(days=1)
last_month_start = last_month_end.replace(day=1)
ranges = {"yesterday": (yesterday_start, yesterday_end), "last_month": (last_month_start, last_month_end)}
stats = {"timestamp": int(time.time())}
def run_stats(f):
start_time = time.time()
stats.update(f(config, ranges))
end_time = time.time()
print >>sys.stderr, "%s took %0.2f seconds." % (f.__name__, end_time - start_time)
print >>sys.stderr, "recalculating reddit stats..."
run_stats(subreddit_stats)
run_stats(vote_stats)
run_stats(traffic_stats)
run_stats(ga_stats)
print >>sys.stderr, "finished:", stats
NamedGlobals.set("about_reddit_stats", stats)
示例8: GET_index
def GET_index(self):
quote = self._get_quote()
images = self._get_images()
stats = NamedGlobals.get('about_reddit_stats', None)
c.js_preload.set('#images', images)
content = About(
quote=quote,
images=images,
stats=stats,
events=g.plugins['about'].timeline_data,
sites=g.plugins['about'].sites_data,
)
return AboutPage(
content_id='about-main',
title_msg=_('we power awesome communities.'),
pagename=_('about reddit'),
content=content,
).render()
示例9: health_check
def health_check():
"""Calculate the number of seconds since promotions were last updated"""
return time.time() - int(NamedGlobals.get(PROMO_HEALTH_KEY, default=0))
示例10: _mark_promos_updated
def _mark_promos_updated():
NamedGlobals.set(PROMO_HEALTH_KEY, time.time())
示例11: get_trending_subreddits
def get_trending_subreddits():
return NamedGlobals.get(TRENDING_SUBREDDITS_KEY, None)
示例12: health_check
def health_check():
return NamedGlobals.get(PROMO_HEALTH_KEY, default=0)
示例13: set_current_press
def set_current_press(press_time):
key = _CURRENT_PRESS_KEY()
serialized = _serialize_datetime(press_time)
NamedGlobals.set(key, serialized)
g.thebuttoncache.set(key, serialized)
g.thebuttoncache.incr(_PARTICIPANTS_KEY())
示例14: mark_timer_expired
def mark_timer_expired(expiration_time):
key = _EXPIRED_KEY()
serialized = _serialize_datetime(expiration_time)
NamedGlobals.set(key, serialized)
g.thebuttoncache.set(key, serialized)