aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2012-05-17 08:54:23 +0200
committercedricbonhomme <devnull@localhost>2012-05-17 08:54:23 +0200
commit71e5ba35f069c09ef9e5faba92ed35095fbf5f86 (patch)
treef233ea9cc2f8ee0a04a47a2ddbe4d97c4dbc21fc
parentMinor bugfix in mongodb.py: delete_article function didn't delete articles. (diff)
downloadnewspipe-71e5ba35f069c09ef9e5faba92ed35095fbf5f86.tar.gz
newspipe-71e5ba35f069c09ef9e5faba92ed35095fbf5f86.tar.bz2
newspipe-71e5ba35f069c09ef9e5faba92ed35095fbf5f86.zip
Improvement: get_articles_from_collection() function can now return only the last 10 articles.
-rw-r--r--source/mongodb.py16
-rwxr-xr-xsource/pyAggr3g470r.py35
2 files changed, 30 insertions, 21 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
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index 6d873ccd..17cfb549 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -158,7 +158,7 @@ class Root:
feed["feed_link"], feed["feed_image"])
# The main page display only 10 articles by feeds.
- for article in self.mongo.get_articles_from_collection(feed["feed_id"])[:10]:
+ for article in self.mongo.get_articles_from_collection(feed["feed_id"], limit=10):
if article["article_readed"] == False:
# not readed articles are in bold
not_read_begin, not_read_end = "<b>", "</b>"
@@ -563,7 +563,7 @@ class Root:
"""
try:
feed = self.mongo.get_feed(feed_id)
- articles = self.mongo.get_articles_from_collection(feed_id)
+ articles = self.mongo.get_articles_from_collection(feed_id, limit=10)
nb_articles_feed = self.mongo.nb_articles(feed_id)
nb_articles_total = self.mongo.nb_articles()
nb_unread_articles_feed = self.mongo.nb_unread_articles(feed_id)
@@ -596,7 +596,7 @@ class Root:
(str(articles[nb_articles_feed-2]["article_date"])[:10], str(articles[0]["article_date"])[:10])
html += "<br /><h1>Recent articles</h1>"
- for article in articles[:10]:
+ for article in articles:
if article["article_readed"] == False:
# not readed articles are in bold
not_read_begin, not_read_end = "<b>", "</b>"
@@ -629,23 +629,22 @@ class Root:
html += "<br />\n"
html += """<a href="/articles/%s">All articles</a>&nbsp;&nbsp;&nbsp;""" % (feed["feed_id"],)
- favs = [article for article in articles if article["article_like"] == True]
- if len(favs) != 0:
+
+ if self.mongo.nb_favorites(feed_id) != 0:
html += "<br /></br /><h1>Your favorites articles for this feed</h1>"
- for article in favs:
- if article["like"] == True:
- # descrition for the CSS ToolTips
- article_content = utils.clear_string(article["article_content"])
- if article_content:
- description = " ".join(article_content[:500].split(' ')[:-1])
- else:
- description = "No description."
+ for article in self.mongo.get_favorites(feed_id):
+ #descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
- # a description line per article (date, title of the article and
- # CSS description tooltips on mouse over)
- html += article["article_date"].ctime() + " - " + \
- """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s<span class="classic">%s</span></a><br />\n""" % \
- (feed["feed_id"], article["article_id"], article["article_title"][:150], description)
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s<span class="classic">%s</span></a><br />\n""" % \
+ (feed["feed_id"], article["article_id"], article["article_title"][:150], description)
# This section enables the user to edit informations about
bgstack15