From cca24c8642e0a86fcad71411a8b3442432f99696 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Fri, 26 Feb 2010 13:14:14 +0100 Subject: Added a link to the feed (on image of feeds). Enhancement of the management of the memory. --- pyAggr3g470r.py | 96 ++++++++++++++++++++++++++++++--------------------------- utils.py | 41 +++++++++++------------- 2 files changed, 68 insertions(+), 69 deletions(-) diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 80edb43f..519e8d3d 100644 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -62,7 +62,7 @@ class Root: """ Main page containing the list of feeds and articles. """ - self.dic, self.dic_info = utils.load_feed() + self.articles, self.feeds = utils.load_feed() html = htmlheader html += htmlnav html += """
\n""" @@ -72,30 +72,33 @@ class Root: html += """
\n""" html += "
\n" - html += """Your feeds (%s):
\n""" % len(self.dic.keys()) - for rss_feed_id in self.dic.keys(): + html += """Your feeds (%s):
\n""" % len(self.articles.keys()) + for rss_feed_id in self.articles.keys(): html += """%s (%s / %s)
\n""" % \ (rss_feed_id.encode('utf-8'), \ - self.dic[rss_feed_id][0][5].encode('utf-8'), \ - rss_feed_id, self.dic_info[rss_feed_id][1], \ - self.dic_info[rss_feed_id][0]) + self.feeds[rss_feed_id][3].encode('utf-8'), \ + rss_feed_id, self.feeds[rss_feed_id][1], \ + self.feeds[rss_feed_id][0]) html += """
\n
\n""" - for rss_feed_id in self.dic.keys(): + for rss_feed_id in self.articles.keys(): html += """

%s -

\n""" % \ - (rss_feed_id, self.dic[rss_feed_id][0][6].encode('utf-8'), \ - self.dic[rss_feed_id][0][5].encode('utf-8'), \ - self.dic_info[rss_feed_id][2].encode('utf-8')) + \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')) # The main page display only 10 articles by feeds. - for article in self.dic[rss_feed_id][:10]: + for article in self.articles[rss_feed_id][:10]: - if article[7] == "0": + if article[5] == "0": # not readed articles are in bold not_read_begin = "" not_read_end = "" @@ -113,10 +116,10 @@ class Root: html += """All articles""" % (rss_feed_id,) html += """ Mark all as read""" % (rss_feed_id,) - if self.dic_info[rss_feed_id][1] != 0: + if self.feeds[rss_feed_id][1] != 0: html += """ Unread article(s) (%s)""" % (rss_feed_id, \ - self.dic_info[rss_feed_id][1]) + self.feeds[rss_feed_id][1]) html += """

Top

""" html += "
\n" html += htmlfooter @@ -128,7 +131,7 @@ class Root: def management(self): """ """ - self.dic, self.dic_info = utils.load_feed() + self.articles, self.feeds = utils.load_feed() html = htmlheader html += htmlnav html += """
\n""" @@ -138,17 +141,17 @@ class Root: html += "

Delete Feeds

\n" html += """
\n""" html += "
\n" html += """

The database contains a total of %s articles with %s unread articles.
""" % \ - (sum([feed[0] for feed in self.dic_info.values()]), - sum([feed[1] for feed in self.dic_info.values()])) + (sum([feed[0] for feed in self.feeds.values()]), + 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")) @@ -158,9 +161,9 @@ class Root: type="submit" value="Delete all articles">\n""" html += "
\n" - if self.dic: + if self.articles: html += "

Statistics

\n" - top_words = utils.top_words(self.dic, 10) + top_words = utils.top_words(self.articles, 10) html += "\n
" html += "
    \n" @@ -194,10 +197,10 @@ class Root: html += """

    Articles containing the string %s


    """ % (querystring,) if feed_id is not None: - for article in self.dic[rss_feed_id]: - article_content = utils.remove_html_tags(article[4].encode('utf-8') + article[2].encode('utf-8')) + for article in self.articles[rss_feed_id]: + article_content = utils.remove_html_tags(article[4].encode('utf-8')) if querystring.lower() in article_content.lower(): - if article[7] == "0": + if article[5] == "0": # not readed articles are in bold not_read_begin = "" not_read_end = "" @@ -211,11 +214,11 @@ class Root: (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ not_read_end else: - for rss_feed_id in self.dic.keys(): - for article in self.dic[rss_feed_id]: - article_content = utils.remove_html_tags(article[4].encode('utf-8') + article[2].encode('utf-8')) + for rss_feed_id in self.articles.keys(): + for article in self.articles[rss_feed_id]: + article_content = utils.remove_html_tags(article[4].encode('utf-8')) if querystring.lower() in article_content.lower(): - if article[7] == "0": + if article[5] == "0": # not readed articles are in bold not_read_begin = "" not_read_end = "" @@ -228,7 +231,8 @@ class Root: """%s""" % \ (article[0].encode('utf-8'), article[2].encode('utf-8')) + \ not_read_end + """ from %s
    \n""" % \ - (article[6].encode('utf-8'), article[5].encode('utf-8')) + (self.feeds[rss_feed_id][5].encode('utf-8'), \ + self.feeds[rss_feed_id][3].encode('utf-8')) html += "
    " html += htmlfooter return html @@ -254,11 +258,11 @@ class Root: html = htmlheader html += htmlnav html += """
    """ - for rss_feed_id in self.dic.keys(): - for article in self.dic[rss_feed_id]: + for rss_feed_id in self.articles.keys(): + for article in self.articles[rss_feed_id]: if article_id == article[0]: - if article[7] == "0": + if article[5] == "0": self.mark_as_read("Article:"+article[3]) # update the database html += """

    %s from %s


    """ % \ @@ -313,21 +317,21 @@ class Root: html += """
    \n
    \n""" % (feed_id,) html += "
    \n" - html += """Your feeds (%s):
    \n""" % len(self.dic.keys()) - for rss_feed_id in self.dic.keys(): + html += """Your feeds (%s):
    \n""" % len(self.articles.keys()) + for rss_feed_id in self.articles.keys(): html += """%s (%s / %s)
    \n""" % \ (rss_feed_id.encode('utf-8'), \ - self.dic[rss_feed_id][0][5].encode('utf-8'), \ - rss_feed_id, self.dic_info[rss_feed_id][1], \ - self.dic_info[rss_feed_id][0]) + self.feeds[rss_feed_id][3].encode('utf-8'), \ + rss_feed_id, self.feeds[rss_feed_id][1], \ + self.feeds[rss_feed_id][0]) html += """
    """ - html += """

    Articles of the feed %s


    """ % (self.dic[feed_id][0][5].encode('utf-8')) + html += """

    Articles of the feed %s


    """ % (self.feeds[feed_id][3].encode('utf-8')) - for article in self.dic[feed_id]: + for article in self.articles[feed_id]: - if article[7] == "0": + if article[5] == "0": # not readed articles are in bold not_read_begin = "" not_read_end = "" @@ -358,11 +362,11 @@ class Root: html += htmlnav html += """
    """ html += """

    Unread article(s) of the feed %s

    -
    """ % (feed_id, self.dic[feed_id][0][5].encode('utf-8')) +
    """ % (feed_id, self.feeds[feed_id][3].encode('utf-8')) - for article in self.dic[feed_id]: + for article in self.articles[feed_id]: - if article[7] == "0": + if article[5] == "0": html += article[1].encode('utf-8') + \ """ - %s""" % \ @@ -392,7 +396,7 @@ class Root: c.execute("UPDATE articles SET article_readed=1") # Mark all articles from a feed as read. elif param == "Feed" or param == "Feed_FromMainPage": - c.execute("UPDATE articles SET article_readed=1 WHERE feed_link='" + self.dic[identifiant][0][6] + "'") + c.execute("UPDATE articles SET article_readed=1 WHERE feed_link='" + self.feeds[identifiant][4].encode('utf-8') + "'") # Mark an article as read. elif param == "Article": c.execute("UPDATE articles SET article_readed=1 WHERE article_link='" + identifiant + "'") @@ -401,7 +405,7 @@ class Root: except Exception, e: pass - self.dic, self.dic_info = utils.load_feed() + self.articles, self.feeds = utils.load_feed() if param == "All" or param == "Feed_FromMainPage": return self.index() diff --git a/utils.py b/utils.py index 4ca97e80..4289a7ee 100644 --- a/utils.py +++ b/utils.py @@ -122,21 +122,16 @@ def load_feed(): pass # The key of dic is the id of the feed: - # dic[feed_id] = (article_id, article_date, article_title, - # article_link, article_description, feed_title, - # feed_link, article_readed) - # dic_info[feed_id] = (nb_article, nb_article_unreaded, feed_image) - dic, dic_info = {}, {} + # articles[feed_id] = (article_id, article_date, article_title, + # article_link, article_description, article_readed) + # feeds[feed_id] = (nb_article, nb_article_unreaded, feed_image, + # feed_title, feed_link, feed_site_link) + articles, feeds = {}, {} if list_of_feeds is not None: for feed in list_of_feeds: - feed_title = feed[0] - feed_site_link = feed[1] - feed_link = feed[2] - feed_image = feed[3] - list_of_articles = c.execute(\ "SELECT * FROM articles WHERE feed_link='" + \ - feed_link + "'").fetchall() + feed[2] + "'").fetchall() if list_of_articles is not None: for article in list_of_articles: @@ -147,23 +142,23 @@ def load_feed(): article_id = sha256_hash.hexdigest() article_list = [article_id, article[0], article[1], \ - article[2], article[3], feed_title, feed_link, article[4]] + article[2], article[3], article[4]] - if feed_id not in dic: - dic[feed_id] = [article_list] + if feed_id not in articles: + articles[feed_id] = [article_list] else: - dic[feed_id].append(article_list) + articles[feed_id].append(article_list) # sort articles by date for each feeds - for feeds in dic.keys(): - dic[feeds].sort(lambda x,y: compare(y[1], x[1])) + for rss_feed_id in articles.keys(): + articles[rss_feed_id].sort(lambda x,y: compare(y[1], x[1])) - dic_info[feed_id] = (len(dic[feed_id]), \ - len([article for article in dic[feed_id] \ - if article[7]=="0"]), \ - feed_image + feeds[feed_id] = (len(articles[feed_id]), \ + len([article for article in articles[feed_id] \ + if article[5]=="0"]), \ + feed[3], feed[0], feed[2], feed[1] \ ) c.close() - return (dic, dic_info) - return (dic, dic_info) \ No newline at end of file + return (articles, feeds) + return (articles, feeds) \ No newline at end of file -- cgit