aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-02-26 13:14:14 +0100
committercedricbonhomme <devnull@localhost>2010-02-26 13:14:14 +0100
commitcca24c8642e0a86fcad71411a8b3442432f99696 (patch)
tree5a3aa17587f10f073c45b12f2a6890d0cdb15e27
parentMinor enhancement. (diff)
downloadnewspipe-cca24c8642e0a86fcad71411a8b3442432f99696.tar.gz
newspipe-cca24c8642e0a86fcad71411a8b3442432f99696.tar.bz2
newspipe-cca24c8642e0a86fcad71411a8b3442432f99696.zip
Added a link to the feed (on image of feeds). Enhancement of the management of the memory.
-rw-r--r--pyAggr3g470r.py96
-rw-r--r--utils.py41
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 += """<div class="right inner">\n"""
@@ -72,30 +72,33 @@ class Root:
html += """<form method=get action="/q/"><input type="text" name="querystring" value=""><input
type="submit" value="Search"></form>\n"""
html += "<hr />\n"
- html += """Your feeds (%s):<br />\n""" % len(self.dic.keys())
- for rss_feed_id in self.dic.keys():
+ html += """Your feeds (%s):<br />\n""" % len(self.articles.keys())
+ for rss_feed_id in self.articles.keys():
html += """<a href="/#%s">%s</a> (<a href="/unread/%s"
title="Unread article(s)">%s</a> / %s)<br />\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 += """</div>\n<div class="left inner">\n"""
- for rss_feed_id in self.dic.keys():
+ for rss_feed_id in self.articles.keys():
html += """<h2><a name="%s"><a href="%s" rel="noreferrer"
target="_blank">%s</a></a>
- <img src="%s" width="28" height="28" /></h2>\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'))
+ <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'))
# 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 = "<b>"
not_read_end = "</b>"
@@ -113,10 +116,10 @@ class Root:
html += """<a href="/all_articles/%s">All articles</a>""" % (rss_feed_id,)
html += """ <a href="/mark_as_read/Feed_FromMainPage:%s">Mark all as read</a>""" % (rss_feed_id,)
- if self.dic_info[rss_feed_id][1] != 0:
+ if self.feeds[rss_feed_id][1] != 0:
html += """ <a href="/unread/%s" title="Unread article(s)"
>Unread article(s) (%s)</a>""" % (rss_feed_id, \
- self.dic_info[rss_feed_id][1])
+ self.feeds[rss_feed_id][1])
html += """<h4><a href="/#top">Top</a></h4>"""
html += "<hr />\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 += """</div> <div class="left inner">\n"""
@@ -138,17 +141,17 @@ class Root:
html += "<h1>Delete Feeds</h1>\n"
html += """<form method=get action="del_feed/"><select name="feed_list">\n"""
- for feed_id in self.dic.keys():
+ for feed_id in self.articles.keys():
html += """\t<option value="%s">%s</option>\n""" % \
- (feed_id, self.dic[feed_id][0][5].encode('utf-8'))
+ (feed_id, self.feeds[feed_id][3].encode('utf-8'))
html += """</select></form>\n"""
html += "<hr />\n"
html += """<p>The database contains a total of %s articles with
%s unread articles.<br />""" % \
- (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<br />Size: %s bytes.</p>\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"></form>\n"""
html += "<hr />\n"
- if self.dic:
+ if self.articles:
html += "<h1>Statistics</h1>\n"
- top_words = utils.top_words(self.dic, 10)
+ top_words = utils.top_words(self.articles, 10)
html += "<table border=0>\n<tr><td>"
html += "<ol>\n"
@@ -194,10 +197,10 @@ class Root:
html += """<h1>Articles containing the string <i>%s</i></h1><br />""" % (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 = "<b>"
not_read_end = "</b>"
@@ -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 = "<b>"
not_read_end = "</b>"
@@ -228,7 +231,8 @@ class Root:
"""<a href="/description/%s" rel="noreferrer" target="_blank">%s</a>""" % \
(article[0].encode('utf-8'), article[2].encode('utf-8')) + \
not_read_end + """ from <i><a href="%s">%s</a></i><br />\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 += "<hr />"
html += htmlfooter
return html
@@ -254,11 +258,11 @@ class Root:
html = htmlheader
html += htmlnav
html += """</div> <div class="left inner">"""
- 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 += """<h1><i>%s</i> from <a href="/all_articles/%s">%s</a></h1><br />""" % \
@@ -313,21 +317,21 @@ class Root:
html += """<br />\n<form method=get action="/q/Feed"><input type="text" name="Feed:%s:querystring" value=""><input
type="submit" value="Search this feed"></form>\n""" % (feed_id,)
html += "<hr />\n"
- html += """Your feeds (%s):<br />\n""" % len(self.dic.keys())
- for rss_feed_id in self.dic.keys():
+ html += """Your feeds (%s):<br />\n""" % len(self.articles.keys())
+ for rss_feed_id in self.articles.keys():
html += """<a href="/#%s">%s</a> (<a href="/unread/%s"
title="Unread article(s)">%s</a> / %s)<br />\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 += """</div> <div class="left inner">"""
- html += """<h1>Articles of the feed <i>%s</i></h1><br />""" % (self.dic[feed_id][0][5].encode('utf-8'))
+ html += """<h1>Articles of the feed <i>%s</i></h1><br />""" % (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 = "<b>"
not_read_end = "</b>"
@@ -358,11 +362,11 @@ class Root:
html += htmlnav
html += """</div> <div class="left inner">"""
html += """<h1>Unread article(s) of the feed <a href="/all_articles/%s">%s</a></h1>
- <br />""" % (feed_id, self.dic[feed_id][0][5].encode('utf-8'))
+ <br />""" % (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') + \
""" - <a href="/description/%s" rel="noreferrer" target="_blank">%s</a>""" % \
@@ -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
bgstack15