Adding days arg to popular stories to grab even more.

This commit is contained in:
Samuel Clay 2012-08-22 11:00:08 -07:00
parent 7f42a7ae10
commit 619efc8b83

View file

@ -1155,11 +1155,11 @@ class MSharedStory(mongo.Document):
story.save()
@classmethod
def collect_popular_stories(cls, cutoff=None):
def collect_popular_stories(cls, cutoff=None, days=1):
from apps.statistics.models import MStatistics
shared_stories_count = sum(json.decode(MStatistics.get('stories_shared')))
cutoff = cutoff or max(math.floor(.05 * shared_stories_count), 3)
today = datetime.datetime.now() - datetime.timedelta(days=1)
today = datetime.datetime.now() - datetime.timedelta(days=days)
map_f = """
function() {
@ -1194,11 +1194,11 @@ class MSharedStory(mongo.Document):
return stories, cutoff
@classmethod
def share_popular_stories(cls, cutoff=None, verbose=True):
def share_popular_stories(cls, cutoff=None, days=None, verbose=True):
publish_new_stories = False
popular_profile = MSocialProfile.objects.get(username='popular')
popular_user = User.objects.get(pk=popular_profile.user_id)
shared_stories_today, cutoff = cls.collect_popular_stories(cutoff=cutoff)
shared_stories_today, cutoff = cls.collect_popular_stories(cutoff=cutoff, days=days)
for guid, story_info in shared_stories_today.items():
story, _ = MStory.find_story(story_info['feed_id'], story_info['guid'])
if not story: