From 5c60263e78be593e6df4ce83fd5bed85207b614f Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 18 Oct 2010 09:01:28 +0200 Subject: Improvements of the page of unread articles and optimization of the top_words() function. --- pyAggr3g470r.py | 85 +++++++++++++++++++++++++++++---------------------------- utils.py | 10 +++---- 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 += """
""" - if feed_id == "All": - html += "

Unread article(s)

" - html += """\n
\nMark articles as read\n
\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 += "

Unread article(s)

" + html += """\n
\nMark articles as read\n
\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 += """

%s +

\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') + \ + """ - %s
\n""" % \ + (rss_feed_id, article[0].encode('utf-8'), \ + article[2].encode('utf-8')) + + if nb_unread == self.feeds[rss_feed_id][1]: + html += """
\nMark all articles from this feed as read\n""" % \ + (rss_feed_id,) + html += """
\nMark articles as read\n""" + else: + try: + articles_list = self.articles[feed_id] + except KeyError: + return self.error_page("This feed do not exists.") + html += """

Unread article(s) of the feed %s

+
""" % (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 += """

%s -

\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') + \ - """ - %s
\n""" % \ - (rss_feed_id, article[0].encode('utf-8'), \ - article[2].encode('utf-8')) - - if nb_unread == self.feeds[rss_feed_id][1]: - html += """
\nMark all articles from this feed as read\n""" % \ - (rss_feed_id,) - html += """
\nMark articles as read\n""" + """ - %s""" % \ + (feed_id, article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + "
\n" + html += """
\nMark all as read""" % (feed_id,) else: - try: - articles_list = self.articles[feed_id] - except KeyError: - return self.error_page("This feed do not exists.") - html += """

Unread article(s) of the feed %s

-
""" % (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') + \ - """ - %s""" % \ - (feed_id, article[0].encode('utf-8'), article[2].encode('utf-8')) + \ - "
\n" - html += """
\nMark all as read""" % (feed_id,) + html += "

No unread article(s)

" html += """\n

All feeds

""" html += "
\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"): -- cgit