From d483562b5f7e934fda0df25ad4399474412a8136 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 8 Mar 2010 18:59:56 +0100 Subject: Improvement. Faster display of some pages (using oice.langdet module). --- pyAggr3g470r.py | 42 ++++++++++++++++++++++++------------------ utils.py | 4 ++-- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 2fc0e442..4d979f14 100644 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -64,7 +64,6 @@ class Root: """ Main page containing the list of feeds and articles. """ - self.articles, self.feeds = utils.load_feed() html = htmlheader html += htmlnav html += """
\n""" @@ -134,7 +133,6 @@ class Root: """ Management of articles. """ - self.articles, self.feeds = utils.load_feed() html = htmlheader html += htmlnav html += """
\n""" @@ -150,10 +148,9 @@ class Root: html += """\n""" html += "
\n" - nb_articles = sum([feed[0] for feed in self.feeds.values()]) html += """

The database contains a total of %s article(s) with %s unread article(s).
""" % \ - (nb_articles, sum([feed[1] for feed in self.feeds.values()])) + (self.nb_articles, sum([feed[1] for feed in self.feeds.values()])) html += """Database: %s.\n
Size: %s bytes.

\n""" % \ (os.path.abspath("./var/feed.db"), os.path.getsize("./var/feed.db")) @@ -165,11 +162,6 @@ class Root: html += "
\n" if self.articles: html += "

Statistics

\n" - - top_words = utils.top_words(self.articles, 10) - if "pylab" not in utils.IMPORT_ERROR: - utils.create_histogram(top_words) - if "oice" not in utils.IMPORT_ERROR: nb_french = 0 nb_english = 0 @@ -179,12 +171,12 @@ class Root: nb_french += 1 elif article[6] == 'english': nb_english += 1 - nb_other = nb_articles - nb_french - nb_english + nb_other = self.nb_articles - nb_french - nb_english html += "\n
" html += "

Words count

\n" html += "
    \n" - for word, frequency in top_words: + for word, frequency in self.top_words: html += """\t
  1. %s: %s
  2. \n""" % \ (word, word, frequency) html += "
\n" @@ -237,8 +229,8 @@ class Root: html += article[1].encode('utf-8') + \ " - " + not_read_begin + \ - """%s""" % \ - (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + """%s""" % \ + (feed_id, article[0].encode('utf-8'), article[2].encode('utf-8')) + \ not_read_end else: for rss_feed_id in self.articles.keys(): @@ -255,8 +247,8 @@ class Root: html += article[1].encode('utf-8') + \ " - " + not_read_begin + \ - """%s""" % \ - (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ + """%s""" % \ + (rss_feed_id, article[0].encode('utf-8'), article[2].encode('utf-8')) + \ not_read_end + """ from %s
\n""" % \ (self.feeds[rss_feed_id][5].encode('utf-8'), \ self.feeds[rss_feed_id][3].encode('utf-8')) @@ -273,6 +265,7 @@ class Root: """ feed_getter = feedgetter.FeedGetter() feed_getter.retrieve_feed() + self.update() return self.index() fetch.exposed = True @@ -439,9 +432,9 @@ class Root: for article in self.articles[rss_feed_id]: if article[6] == lang: html += article[1].encode('utf-8') + \ - """ - %s + """ - %s from %s
\n""" % \ - (article[0].encode('utf-8'), article[2].encode('utf-8'), \ + (rss_feed_id, article[0].encode('utf-8'), article[2].encode('utf-8'), \ self.feeds[rss_feed_id][5].encode('utf-8'), \ self.feeds[rss_feed_id][3].encode('utf-8')) else: @@ -503,7 +496,7 @@ class Root: except Exception, e: pass - self.articles, self.feeds = utils.load_feed() + self.update() if param == "All" or param == "Feed_FromMainPage": return self.index() @@ -513,9 +506,22 @@ class Root: mark_as_read.exposed = True + def update(self): + """ + Synchronizes transient objects with the database, + computes the list of most frequent words and generates the histogram. + Called when an article is marked as read or when new articles are fetched. + """ + self.articles, self.feeds = utils.load_feed() + if self.articles != {}: + self.nb_articles = sum([feed[0] for feed in self.feeds.values()]) + self.top_words = utils.top_words(self.articles, 10) + if "pylab" not in utils.IMPORT_ERROR: + utils.create_histogram(self.top_words) if __name__ == '__main__': # Point of entry in execution mode root = Root() + root.update() cherrypy.quickstart(root, config=path) \ No newline at end of file diff --git a/utils.py b/utils.py index f7c7d351..7b1d7285 100644 --- a/utils.py +++ b/utils.py @@ -2,8 +2,8 @@ #-*- coding: utf-8 -*- __author__ = "Cedric Bonhomme" -__version__ = "$Revision: 0.1 $" -__date__ = "$Date: 2010/02/24 $" +__version__ = "$Revision: 0.2 $" +__date__ = "$Date: 2010/03/07 $" __copyright__ = "Copyright (c) 2010 Cedric Bonhomme" __license__ = "GPLv3" -- cgit