aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-10-18 09:01:28 +0200
committercedricbonhomme <devnull@localhost>2010-10-18 09:01:28 +0200
commit5c60263e78be593e6df4ce83fd5bed85207b614f (patch)
tree3197222dd788d23b4fe1873d06665bd7ab392082
parentUpdated README. (diff)
downloadnewspipe-5c60263e78be593e6df4ce83fd5bed85207b614f.tar.gz
newspipe-5c60263e78be593e6df4ce83fd5bed85207b614f.tar.bz2
newspipe-5c60263e78be593e6df4ce83fd5bed85207b614f.zip
Improvements of the page of unread articles and optimization of the top_words() function.
-rwxr-xr-xpyAggr3g470r.py85
-rwxr-xr-xutils.py10
2 files changed, 48 insertions, 47 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py
index 770438da..584ec9a5 100755
--- a/pyAggr3g470r.py
+++ b/pyAggr3g470r.py
@@ -564,50 +564,53 @@ class Root:
html = htmlheader()
html += htmlnav
html += """<div class="left inner">"""
- if feed_id == "All":
- html += "<h1>Unread article(s)</h1>"
- html += """\n<br />\n<a href="/mark_as_read/All:">Mark articles as read</a>\n<hr />\n"""
- for rss_feed_id in self.feeds.keys():
- new_feed_section = True
- nb_unread = 0
- for article in self.articles[rss_feed_id]:
+ if self.nb_unread_articles != 0:
+ if feed_id == "All":
+ html += "<h1>Unread article(s)</h1>"
+ html += """\n<br />\n<a href="/mark_as_read/All:">Mark articles as read</a>\n<hr />\n"""
+ for rss_feed_id in self.feeds.keys():
+ new_feed_section = True
+ nb_unread = 0
+ for article in self.articles[rss_feed_id]:
+ if article[5] == "0":
+ nb_unread += 1
+ if new_feed_section is True:
+ new_feed_section = False
+ html += """<h2><a name="%s"><a href="%s" rel="noreferrer"
+ target="_blank">%s</a></a>
+ <a href="%s" rel="noreferrer"
+ target="_blank"><img src="%s" width="28" height="28" /></a></h2>\n""" % \
+ (rss_feed_id, \
+ self.feeds[rss_feed_id][5].encode('utf-8'), \
+ self.feeds[rss_feed_id][3].encode('utf-8'), \
+ self.feeds[rss_feed_id][4].encode('utf-8'), \
+ self.feeds[rss_feed_id][2].encode('utf-8'))
+
+ html += article[1].encode('utf-8') + \
+ """ - <a href="/description/%s:%s" rel="noreferrer" target="_blank">%s</a><br />\n""" % \
+ (rss_feed_id, article[0].encode('utf-8'), \
+ article[2].encode('utf-8'))
+
+ if nb_unread == self.feeds[rss_feed_id][1]:
+ html += """<br />\n<a href="/mark_as_read/Feed:%s">Mark all articles from this feed as read</a>\n""" % \
+ (rss_feed_id,)
+ html += """<hr />\n<a href="/mark_as_read/All:">Mark articles as read</a>\n"""
+ else:
+ try:
+ articles_list = self.articles[feed_id]
+ except KeyError:
+ return self.error_page("This feed do not exists.")
+ html += """<h1>Unread article(s) of the feed <a href="/all_articles/%s">%s</a></h1>
+ <br />""" % (feed_id, self.feeds[feed_id][3].encode('utf-8'))
+ for article in articles_list:
if article[5] == "0":
- nb_unread += 1
- if new_feed_section is True:
- new_feed_section = False
- html += """<h2><a name="%s"><a href="%s" rel="noreferrer"
- target="_blank">%s</a></a>
- <a href="%s" rel="noreferrer"
- target="_blank"><img src="%s" width="28" height="28" /></a></h2>\n""" % \
- (rss_feed_id, \
- self.feeds[rss_feed_id][5].encode('utf-8'), \
- self.feeds[rss_feed_id][3].encode('utf-8'), \
- self.feeds[rss_feed_id][4].encode('utf-8'), \
- self.feeds[rss_feed_id][2].encode('utf-8'))
-
html += article[1].encode('utf-8') + \
- """ - <a href="/description/%s:%s" rel="noreferrer" target="_blank">%s</a><br />\n""" % \
- (rss_feed_id, article[0].encode('utf-8'), \
- article[2].encode('utf-8'))
-
- if nb_unread == self.feeds[rss_feed_id][1]:
- html += """<br />\n<a href="/mark_as_read/Feed:%s">Mark all articles from this feed as read</a>\n""" % \
- (rss_feed_id,)
- html += """<hr />\n<a href="/mark_as_read/All:">Mark articles as read</a>\n"""
+ """ - <a href="/description/%s:%s" rel="noreferrer" target="_blank">%s</a>""" % \
+ (feed_id, article[0].encode('utf-8'), article[2].encode('utf-8')) + \
+ "<br />\n"
+ html += """<hr />\n<a href="/mark_as_read/Feed:%s">Mark all as read</a>""" % (feed_id,)
else:
- try:
- articles_list = self.articles[feed_id]
- except KeyError:
- return self.error_page("This feed do not exists.")
- html += """<h1>Unread article(s) of the feed <a href="/all_articles/%s">%s</a></h1>
- <br />""" % (feed_id, self.feeds[feed_id][3].encode('utf-8'))
- for article in articles_list:
- if article[5] == "0":
- html += article[1].encode('utf-8') + \
- """ - <a href="/description/%s:%s" rel="noreferrer" target="_blank">%s</a>""" % \
- (feed_id, article[0].encode('utf-8'), article[2].encode('utf-8')) + \
- "<br />\n"
- html += """<hr />\n<a href="/mark_as_read/Feed:%s">Mark all as read</a>""" % (feed_id,)
+ html += "<h1>No unread article(s)</h1>"
html += """\n<h4><a href="/">All feeds</a></h4>"""
html += "<hr />\n"
html += htmlfooter
diff --git a/utils.py b/utils.py
index 1ff2a57e..18deff58 100755
--- a/utils.py
+++ b/utils.py
@@ -161,15 +161,13 @@ def top_words(dic_articles, n=10, size=5):
"""
Return the n most frequent words in a list.
"""
- words_gen = []
+ words = Counter()
for rss_feed_id in dic_articles.keys():
for article in dic_articles[rss_feed_id]:
- words_gen.extend([word.strip(punctuation).lower() \
+ for good_word in [word.strip(punctuation).lower() \
for word in clear_string(article[4].encode('utf-8')).split() \
- if len(word.strip(punctuation)) >= size])
- words = Counter()
- for word in words_gen:
- words[word] += 1
+ if len(word.strip(punctuation)) >= size]:
+ words[good_word] += 1
return words.most_common(n)
def tag_cloud(tags, query="word_count"):
bgstack15