diff options
author | cedricbonhomme <devnull@localhost> | 2012-05-17 08:54:23 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2012-05-17 08:54:23 +0200 |
commit | 71e5ba35f069c09ef9e5faba92ed35095fbf5f86 (patch) | |
tree | f233ea9cc2f8ee0a04a47a2ddbe4d97c4dbc21fc /source/mongodb.py | |
parent | Minor bugfix in mongodb.py: delete_article function didn't delete articles. (diff) | |
download | newspipe-71e5ba35f069c09ef9e5faba92ed35095fbf5f86.tar.gz newspipe-71e5ba35f069c09ef9e5faba92ed35095fbf5f86.tar.bz2 newspipe-71e5ba35f069c09ef9e5faba92ed35095fbf5f86.zip |
Improvement: get_articles_from_collection() function can now return only the last 10 articles.
Diffstat (limited to 'source/mongodb.py')
-rw-r--r-- | source/mongodb.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/source/mongodb.py b/source/mongodb.py index d2f87042..9915de75 100644 --- a/source/mongodb.py +++ b/source/mongodb.py @@ -98,15 +98,15 @@ class Articles(object): collection = self.db[str(feed_id)] return collection.find({"article_id":article_id}).next() - def get_articles_from_collection(self, feed_id, condition=None): + def get_articles_from_collection(self, feed_id, condition=None, limit=1000000000): """ Return all the articles of a collection. """ collection = self.db[str(feed_id)] if condition is None: - cursor = collection.find({"type":1}) + cursor = collection.find({"type":1}, limit=limit) else: - cursor = collection.find({"type":1, condition[0]:condition[1]}) + cursor = collection.find({"type":1, condition[0]:condition[1]}, limit=limit) return cursor.sort([("article_date", pymongo.DESCENDING)]) def nb_articles(self, feed_id=None): @@ -124,6 +124,16 @@ class Articles(object): nb_articles += self.nb_articles(feed_id) return nb_articles + def get_favorites(self, feed_id=None): + """ + Return favorites articles. + """ + if feed_id is not None: + # only for a feed + collection = self.db[feed_id] + cursor = collection.find({'type':1, 'article_like':True}) + return cursor + def nb_favorites(self, feed_id=None): """ Return the number of favorites articles of a feed |