aboutsummaryrefslogtreecommitdiff
path: root/source/mongodb.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2012-04-22 22:33:05 +0200
committercedricbonhomme <devnull@localhost>2012-04-22 22:33:05 +0200
commit09fe5a7386221d561f2a04c1d04e6326051fab76 (patch)
tree27156117b734129c212bcdc0fa184ed75569d2b9 /source/mongodb.py
parentRenamed get_all_collections() to get_all_feeds(). (diff)
downloadnewspipe-09fe5a7386221d561f2a04c1d04e6326051fab76.tar.gz
newspipe-09fe5a7386221d561f2a04c1d04e6326051fab76.tar.bz2
newspipe-09fe5a7386221d561f2a04c1d04e6326051fab76.zip
Added comments.
Diffstat (limited to 'source/mongodb.py')
-rw-r--r--source/mongodb.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/source/mongodb.py b/source/mongodb.py
index f40b1239..a89858b0 100644
--- a/source/mongodb.py
+++ b/source/mongodb.py
@@ -63,6 +63,22 @@ class Articles(object):
"""
return self.db[str(feed_id)].find().next()
+ def get_all_feeds(self, condition=None):
+ """
+ """
+ feeds = []
+ collections = self.db.collection_names()
+ for collection_name in collections:
+ if collection_name != "system.indexes":
+ if condition is None:
+ cursor = self.db[collection_name].find({"type":0})
+ else:
+ cursor = self.db[collection_name].find({"type":0, condition[0]:condition[1]})
+ if cursor.count() != 0:
+ feeds.append(cursor.next())
+ feeds.sort(key = lambda elem: elem['feed_title'].lower())
+ return feeds
+
def get_all_articles(self):
"""
Return all articles from all collections.
@@ -76,26 +92,11 @@ class Articles(object):
def get_article(self, feed_id, article_id):
"""
+ Get an article of a specified feed.
"""
collection = self.db[str(feed_id)]
return collection.find({"article_id":article_id}).next()
- def get_all_feeds(self, condition=None):
- """
- """
- feeds = []
- collections = self.db.collection_names()
- for collection_name in collections:
- if collection_name != "system.indexes":
- if condition is None:
- cursor = self.db[collection_name].find({"type":0})
- else:
- cursor = self.db[collection_name].find({"type":0, condition[0]:condition[1]})
- if cursor.count() != 0:
- feeds.append(cursor.next())
- feeds.sort(key = lambda elem: elem['feed_title'].lower())
- return feeds
-
def get_articles_from_collection(self, feed_id, condition=None):
"""
Return all the articles of a collection.
@@ -122,11 +123,16 @@ class Articles(object):
return nb_articles
def nb_favorites(self, feed_id=None):
+ """
+ Return the number of 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.count()
else:
+ # for all feeds
nb_favorites = 0
for feed_id in self.db.collection_names():
nb_favorites += self.nb_favorites(feed_id)
bgstack15