Skip to content
This repository was archived by the owner on Mar 7, 2018. It is now read-only.

"Fresh Posts" feature #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added get_fresh_posts(hours=1, quantity=1) method
This method gets the #{quantity} latest posts submitted within the past #{hours}. By default, it returns a post (dubbed "Fresh") if it is new, not featured, and was submitted within the past hour.
jmonegro committed Apr 22, 2014
commit cb503b69bcf914b0b44f2de98e167a0bf8c6a6c7
7 changes: 6 additions & 1 deletion lib/postsdb.py
Original file line number Diff line number Diff line change
@@ -86,6 +86,11 @@ def get_hot_posts_by_day(day=date.today()):
day_plus_one = day + timedelta(days=1)
return list(db.post.find({"deleted": { "$ne": True }, 'date_created': {'$gte': day, '$lte': day_plus_one}}, sort=[('daily_sort_score', pymongo.DESCENDING)]))

def get_fresh_posts(hours=1, quantity=1):
hours_ago = datetime.today() - timedelta(hours=hours)
now = datetime.today()
return list(db.post.find({"deleted": { "$ne": True }, 'featured':False,'date_created': {'$gte': hours_ago, '$lte': now}}, sort=[('_id', pymongo.DESCENDING)]).limit(quantity))

def get_daily_posts_by_sort_score(min_score=8):
day=date.today()
day = datetime.combine(day, datetime.min.time())
@@ -244,4 +249,4 @@ def sort_posts(day="all"):
print "-- %s" % total_score
print "---- %s" % json.dumps(scores, indent=4)

print "All posts sorted!"
print "All posts sorted!"