aboutsummaryrefslogtreecommitdiff
path: root/source/mongodb.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2012-11-30 18:13:27 +0100
committerCédric Bonhomme <kimble.mandel@gmail.com>2012-11-30 18:13:27 +0100
commitbdb9af617a91500c7a045999ff1f74f5f8cdbeae (patch)
tree6abc4d258a75f9cc900a07ffafb2aa5d7592e4f7 /source/mongodb.py
parentCode factorization. (diff)
downloadnewspipe-bdb9af617a91500c7a045999ff1f74f5f8cdbeae.tar.gz
newspipe-bdb9af617a91500c7a045999ff1f74f5f8cdbeae.tar.bz2
newspipe-bdb9af617a91500c7a045999ff1f74f5f8cdbeae.zip
Code factorization...
Diffstat (limited to 'source/mongodb.py')
-rw-r--r--source/mongodb.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/source/mongodb.py b/source/mongodb.py
index 84e81a04..66b2865c 100644
--- a/source/mongodb.py
+++ b/source/mongodb.py
@@ -110,8 +110,12 @@ class Articles(object):
collections = self.db.collection_names()
for collection_name in collections:
collection = self.db[collection_name]
- articles.extend(collection.find({'type':1}))
+ if condition is None:
+ articles.extend(collection.find({"type":1}, limit=limit))
+ else:
+ articles.extend(collection.find({"type":1, condition[0]:condition[1]}, limit=limit))
return articles
+
elif feed_id != None and article_id == None:
# Return all the articles of a collection.
collection = self.db[str(feed_id)]
@@ -120,6 +124,7 @@ class Articles(object):
else:
cursor = collection.find({"type":1, condition[0]:condition[1]}, limit=limit)
return cursor.sort([("article_date", pymongo.DESCENDING)])
+
elif feed_id != None and article_id != None:
# Return a precise article.
collection = self.db[str(feed_id)]
@@ -182,14 +187,9 @@ class Articles(object):
or of all the database.
"""
if feed_id is not None:
- collection = self.db[feed_id]
- cursor = collection.find({'article_readed':False})
- return cursor.count()
+ return self.get_articles(feed_id=feed_id, condition=("article_readed", False)).count()
else:
- unread_articles = 0
- for feed_id in self.db.collection_names():
- unread_articles += self.nb_unread_articles(feed_id)
- return unread_articles
+ return len(self.get_articles(condition=("article_readed", False)))
def like_article(self, like, feed_id, article_id):
"""
bgstack15