aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2012-10-22 08:44:09 +0200
committercedricbonhomme <devnull@localhost>2012-10-22 08:44:09 +0200
commit5a67ce3d2d5ff0f4b6a582fd09585b457881bbb1 (patch)
treec8a7c523c06888ffd5c5845b0c706a821d2d9277
parentBug fix in drop base function. The wrong database name was used. (diff)
downloadnewspipe-5a67ce3d2d5ff0f4b6a582fd09585b457881bbb1.tar.gz
newspipe-5a67ce3d2d5ff0f4b6a582fd09585b457881bbb1.tar.bz2
newspipe-5a67ce3d2d5ff0f4b6a582fd09585b457881bbb1.zip
Minor improvements for the management of the database.
-rw-r--r--source/mongodb.py13
-rwxr-xr-xsource/pyAggr3g470r.py2
2 files changed, 9 insertions, 6 deletions
diff --git a/source/mongodb.py b/source/mongodb.py
index 95d7560c..e83b7324 100644
--- a/source/mongodb.py
+++ b/source/mongodb.py
@@ -37,8 +37,9 @@ class Articles(object):
"""
Instantiates the connection.
"""
+ self.db_name = db_name
self.connection = pymongo.connection.Connection(url, port)
- self.db = pymongo.database.Database(self.connection, db_name)
+ self.db = pymongo.database.Database(self.connection, self.db_name)
self.db.authenticate(user, password)
def add_collection(self, new_collection):
@@ -81,6 +82,7 @@ class Articles(object):
def get_all_feeds(self, condition=None):
"""
+ Return all feeds object.
"""
feeds = []
collections = self.db.collection_names()
@@ -97,13 +99,14 @@ class Articles(object):
def get_all_articles(self):
"""
- Return all articles from all collections.
+ Return articles of all feeds object (articles of all MongoDB articles collections).
+ All articles collections are of type 1.
"""
articles = []
collections = self.db.collection_names()
for collection_name in collections:
collection = self.db[collection_name]
- articles.extend([article for article in collection.find({'type':1})])
+ articles.extend(collection.find({'type':1}))
return articles
def get_article(self, feed_id, article_id):
@@ -227,11 +230,11 @@ class Articles(object):
return collections
# Functions on database
- def drop_database(self, db_name="pyaggr3g470r"):
+ def drop_database(self):
"""
Drop all the database
"""
- self.connection.drop_database(db_name)
+ self.connection.drop_database(self.db_name)
if __name__ == "__main__":
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index 6a71b7f2..2fac78e0 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -1206,7 +1206,7 @@ class pyAggr3g470r(object):
"""
Delete all articles.
"""
- self.mongo.drop_database(conf.MONGODB_DBNAME)
+ self.mongo.drop_database()
return self.index()
drop_base.exposed = True
bgstack15