本文整理汇总了Python中api.API.stories方法的典型用法代码示例。如果您正苦于以下问题:Python API.stories方法的具体用法?Python API.stories怎么用?Python API.stories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api.API
的用法示例。
在下文中一共展示了API.stories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_stories
# 需要导入模块: from api import API [as 别名]
# 或者: from api.API import stories [as 别名]
def update_stories(cache_minutes=20, story_type='news', over_filter=None):
try:
if story_type == 'news' and over_filter:
# Over points can have different values meaning that it can't be cached normal
cachetime = StoryCache.objects.get(name=story_type, over=over_filter).time
else:
cachetime = StoryCache.objects.get(name=story_type, over=None).time
except StoryCache.DoesNotExist:
# Force updating cache
cachetime = timezone.now() - datetime.timedelta(days=1)
# More than cache_minutes since cache was updated
if cachetime + datetime.timedelta(minutes=cache_minutes) < timezone.now():
API.stories(story_type=story_type, over_filter=over_filter)
# Updating cache
if story_type == 'news' and over_filter:
over = over_filter
else:
over = None
story_cache, created = StoryCache.objects.get_or_create(name=story_type, over=over)
story_cache.time = timezone.now()
story_cache.save()
return None
else:
return cachetime