diff options
Diffstat (limited to 'source/mongodb.py')
-rw-r--r-- | source/mongodb.py | 38 |
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) |