From 709cb184523fea649580b0d6219c0fc393a11e77 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 6 Dec 2010 08:20:52 +0100 Subject: Minor improvements. Removed useless .encode('utf-8'). --- articles.py | 2 +- pyAggr3g470r.py | 180 +++++++++++++++++++++++--------------------------------- utils.py | 22 +++---- 3 files changed, 86 insertions(+), 118 deletions(-) diff --git a/articles.py b/articles.py index 7c019ae7..6a37bea8 100644 --- a/articles.py +++ b/articles.py @@ -29,7 +29,7 @@ from collections import OrderedDict class Feed(object): """ - Represent a stream (RSS, ATOM). + Represent a stream (RSS, ATOM, etc.). """ def __init__(self): """ diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 981a906e..8cdde3a2 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -152,11 +152,8 @@ class Root: target="_blank">%s \n""" % \ - (feed.feed_id, \ - feed.feed_site_link.encode('utf-8'), \ - feed.feed_title.encode('utf-8'), \ - feed.feed_link.encode('utf-8'), \ - feed.feed_image.encode('utf-8')) + (feed.feed_id, feed.feed_site_link, feed.feed_title, \ + feed.feed_link, feed.feed_image) # The main page display only 10 articles by feeds. for article in feed.articles.values()[:10]: @@ -176,21 +173,21 @@ class Root: like = "" # Descrition for the CSS ToolTips - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if article_content: description = " ".join(article_content[:500].split(' ')[:-1]) else: description = "No description." # Title of the article - article_title = article.article_title.encode('utf-8') + article_title = article.article_title if len(article_title) >= 110: article_title = article_title[:110] + " ..." # a description line per article (date, title of the article and # CSS description tooltips on mouse over) - html += article.article_date.encode('utf-8') + " - " + \ + html += article.article_date + " - " + \ """%s%s%s%s""" % \ - (feed.feed_id, article.article_id.encode('utf-8'), not_read_begin, \ + (feed.feed_id, article.article_id, not_read_begin, \ article_title, not_read_end, description) + like + "
\n" html += "
\n" @@ -239,8 +236,7 @@ class Root: not_read_end = "" html += """
%s (%s%s%s / %s)
""" % \ - (feed.feed_id.encode('utf-8'), feed.feed_title.encode('utf-8'), \ - feed.feed_id, not_read_begin, \ + (feed.feed_id, feed.feed_title, feed.feed_id, not_read_begin, \ feed.nb_unread_articles, not_read_end, feed.nb_articles) return html + "" @@ -261,7 +257,7 @@ class Root: html += """
\n""" html += """

Active e-mail notifications: %s

\n""" % \ (self.nb_mail_notifications,) @@ -312,7 +308,6 @@ class Root: Search for a feed. Simply search for the string 'querystring' in the description of the article. """ - print querystring param, _, value = querystring.partition(':') wordre = re.compile(r'\b%s\b' % param, re.I) feed_id = None @@ -325,9 +320,9 @@ class Root: if feed_id is not None: for article in self.feeds[feed_id].articles.values(): - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if not article_content: - utils.clear_string(article.article_title.encode('utf-8')) + utils.clear_string(article.article_title) if wordre.findall(article_content) != []: if article.article_readed == "0": # not readed articles are in bold @@ -337,18 +332,18 @@ class Root: not_read_begin = "" not_read_end = "" - html += article.article_date.encode('utf-8') + \ + html += article.article_date + \ " - " + not_read_begin + \ """%s""" % \ - (feed_id, article.article_id.encode('utf-8'), article.article_title.encode('utf-8')) + \ + (feed_id, article.article_id, article.article_title) + \ not_read_end + """
\n""" else: for feed in self.feeds.values(): new_feed_section = True for article in feed.articles.values(): - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if not article_content: - utils.clear_string(article.article_title.encode('utf-8')) + utils.clear_string(article.article_title) if wordre.findall(article_content) != []: if new_feed_section is True: new_feed_section = False @@ -356,11 +351,7 @@ class Root: target="_blank">%s \n""" % \ - (feed.feed_id, \ - feed.feed_id.encode('utf-8'), \ - feed.feed_title.encode('utf-8'), \ - feed.feed_link.encode('utf-8'), \ - feed.feed_image.encode('utf-8')) + (feed.feed_id, feed.feed_id, feed.feed_title, feed.feed_link, feed.feed_image) if article.article_readed == "0": # not readed articles are in bold @@ -377,7 +368,7 @@ class Root: like = "" # descrition for the CSS ToolTips - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if article_content: description = " ".join(article_content[:500].split(' ')[:-1]) else: @@ -385,11 +376,10 @@ class Root: # a description line per article (date, title of the article and # CSS description tooltips on mouse over) - html += article.article_date.encode('utf-8') + " - " + \ + html += article.article_date + " - " + \ """%s%s%s%s""" % \ - (feed.feed_id, article.article_id.encode('utf-8'), not_read_begin, \ - article.article_title.encode('utf-8')[:150], \ - not_read_end, description) + like + "
\n" + (feed.feed_id, article.article_id, not_read_begin, \ + article.article_title[:150], not_read_end, description) + like + "
\n" html += "
" html += htmlfooter return html @@ -445,8 +435,7 @@ class Root: html += '\n
\n' html += """

%s from %s

\n
\n""" % \ - (article.article_title.encode('utf-8'), feed_id, \ - feed.feed_title.encode('utf-8')) + (article.article_title, feed_id, feed.feed_title) if article.like == "1": html += """""" % \ (feed_id, article.article_id) @@ -458,7 +447,7 @@ class Root: html += "

" description = article.article_description if description: - html += description.encode('utf-8') + html += description else: html += "No description available." html += "\n
\n
\n" @@ -467,52 +456,52 @@ class Root: html += """ - Export to EPUB\n""" % \ (feed_id, article.article_id) html += """
\nComplete story\n
\n""" % \ - (article.article_link.encode('utf-8'),) + (article.article_link,) # Share this article: # on Identi.ca html += """\n    \n""" % \ - (article.article_title.encode('utf-8'), article.article_link.encode('utf-8')) + (article.article_title, article.article_link) # on Google Buzz html += """\n\n\n\t    """ % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) + (article.article_link, article.article_title) # on delicious html += """\n\n\n\t    """ % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) + (article.article_link, article.article_title) # on Digg html += """\n\n\n\t    """ % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) + (article.article_link, article.article_title) # on reddit html += """\n\n\n\t    """ % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) + (article.article_link, article.article_title) # on Scoopeo html += """\n\n\n\t    """ % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) + (article.article_link, article.article_title) # on Blogmarks html += """\n\n\n\t    """ % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) + (article.article_link, article.article_title) # on Twitter html += """\n\nTweet\n""" % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) + (article.article_link, article.article_title) # on Google Buzz with counter html += """

\n\n    """ % \ - (article.article_link.encode('utf-8'),) + (article.article_link,) html += """
\n""" % \ (article_id,) @@ -538,7 +527,7 @@ class Root: html += "
\n" html += self.create_list_of_feeds() html += """
""" - html += """

Articles of the feed %s


""" % (feed.feed_title.encode('utf-8')) + html += """

Articles of the feed %s


""" % (feed.feed_title) for article in feed.articles.values(): @@ -556,7 +545,7 @@ class Root: like = "" # descrition for the CSS ToolTips - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if article_content: description = " ".join(article_content[:500].split(' ')[:-1]) else: @@ -564,11 +553,10 @@ class Root: # a description line per article (date, title of the article and # CSS description tooltips on mouse over) - html += article.article_date.encode('utf-8') + " - " + \ + html += article.article_date + " - " + \ """%s%s%s%s""" % \ - (feed.feed_id, article.article_id.encode('utf-8'), not_read_begin, \ - article.article_title.encode('utf-8')[:150], \ - not_read_end, description) + like + "
\n" + (feed.feed_id, article.article_id, not_read_begin, \ + article.article_title[:150], not_read_end, description) + like + "
\n" html += """\n

All feeds

""" html += "
\n" @@ -601,14 +589,10 @@ class Root: target="_blank">%s \n""" % \ - (feed.feed_id, \ - feed.feed_site_link.encode('utf-8'), \ - feed.feed_title.encode('utf-8'), \ - feed.feed_link.encode('utf-8'), \ - feed.feed_image.encode('utf-8')) + (feed.feed_id, feed.feed_site_link, feed.feed_title, feed.feed_link, feed.feed_image) # descrition for the CSS ToolTips - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if article_content: description = " ".join(article_content[:500].split(' ')[:-1]) else: @@ -616,10 +600,9 @@ class Root: # a description line per article (date, title of the article and # CSS description tooltips on mouse over) - html += article.article_date.encode('utf-8') + " - " + \ + html += article.article_date + " - " + \ """%s%s
\n""" % \ - (feed.feed_id, article.article_id.encode('utf-8'), \ - article.article_title.encode('utf-8')[:150], description) + (feed.feed_id, article.article_id, article.article_title[:150], description) if nb_unread == feed.nb_unread_articles: html += """
\nMark all articles from this feed as read\n""" % \ @@ -631,11 +614,11 @@ class Root: except: self.error_page("This feed do not exists.") html += """

Unread article(s) of the feed %s

-
""" % (feed.feed_id, feed.feed_title.encode('utf-8')) +
""" % (feed.feed_id, feed.feed_title) for article in feed.articles.values(): if article.article_readed == "0": # descrition for the CSS ToolTips - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if article_content: description = " ".join(article_content[:500].split(' ')[:-1]) else: @@ -643,10 +626,9 @@ class Root: # a description line per article (date, title of the article and # CSS description tooltips on mouse over) - html += article.article_date.encode('utf-8') + " - " + \ + html += article.article_date + " - " + \ """%s%s
\n""" % \ - (feed.feed_id, article.article_id.encode('utf-8'), \ - article.article_title.encode('utf-8')[:150], description) + (feed.feed_id, article.article_id, article.article_title[:150], description) html += """
\nMark all as read""" % (feed.feed_id,) else: @@ -689,15 +671,15 @@ class Root: for article in feed.articles.values(): if querystring == "all": - timeline[article.article_date.encode('utf-8').split(' ')[0].split('-')[0]] += 1 + timeline[article.article_date.split(' ')[0].split('-')[0]] += 1 elif querystring[:4] == "year": - if article.article_date.encode('utf-8').split(' ')[0].split('-')[0] == the_year: - timeline[article.article_date.encode('utf-8').split(' ')[0].split('-')[1]] += 1 + if article.article_date.split(' ')[0].split('-')[0] == the_year: + timeline[article.article_date.split(' ')[0].split('-')[1]] += 1 if "month" in querystring: - if article.article_date.encode('utf-8').split(' ')[0].split('-')[1] == the_month: + if article.article_date.split(' ')[0].split('-')[1] == the_month: if article.article_readed == "0": # not readed articles are in bold not_read_begin = "" @@ -717,19 +699,12 @@ class Root: target="_blank">%s \n""" % \ - (feed.feed_id, \ - feed.feed_site_link.encode('utf-8'), \ - feed.feed_title.encode('utf-8'), \ - feed.feed_link.encode('utf-8'), \ - feed.feed_image.encode('utf-8')) - - html += article.article_date.encode('utf-8') + \ - " - " + not_read_begin + \ + (feed.feed_id, feed.feed_site_link, feed.feed_title, feed.feed_link, feed.feed_image) + + html += article.article_date + " - " + not_read_begin + \ """%s""" % \ - (feed.feed_id, article.article_id.encode('utf-8'), \ - utils.clear_string(article.article_title.encode('utf-8'))) + \ - not_read_end + like + \ - "
\n" + (feed.feed_id, article.article_id, \ + utils.clear_string(article.article_title)) + not_read_end + like + "
\n" if querystring == "all": query = "year" @@ -737,8 +712,7 @@ class Root: query = "year:" + the_year + "-month" if "month" not in querystring: html += '
' + \ - utils.tag_cloud([(elem, timeline[elem]) for elem in timeline.keys()], \ - query) + '
' + utils.tag_cloud([(elem, timeline[elem]) for elem in timeline.keys()], query) + '
' html += '

Search with a month+year picker

\n' html += '
\n\t\n\t\n
' html += '
' @@ -766,9 +740,8 @@ class Root: html += """
""" feed_id, article_id = target.split(':') html += """

%s from %s

\n
\n"""% \ - (article.article_title.encode('utf-8'), feed_id, \ - feed.feed_title.encode('utf-8')) - description = utils.clear_string(article.article_description.encode('utf-8')) + (article.article_title, feed_id, feed.feed_title) + description = utils.clear_string(article.article_description) if description: html += description else: @@ -809,7 +782,7 @@ class Root: # Mark all articles from a feed as read. elif param == "Feed" or param == "Feed_FromMainPage": c.execute("UPDATE articles SET article_readed=1 WHERE article_readed='0' AND feed_link='" + \ - self.feeds[identifiant].feed_link.encode('utf-8') + "'") + self.feeds[identifiant].feed_link + "'") # Mark an article as read. elif param == "Article": c.execute("UPDATE articles SET article_readed=1 WHERE article_link='" + \ @@ -840,7 +813,7 @@ class Root: for feed in self.feeds.values(): if feed.mail == "1": html += """\t%s - Stop
\n""" % \ - (feed.feed_id, feed.feed_title.encode('utf-8'), feed.feed_id) + (feed.feed_id, feed.feed_title, feed.feed_id) html += """

Notifications are sent to: %s

""" % \ (utils.mail_to, utils.mail_to) @@ -865,13 +838,13 @@ class Root: if action == "start": try: c.execute("UPDATE feeds SET mail=1 WHERE feed_site_link='" + - self.feeds[feed_id].feed_site_link.encode('utf-8') + "'") + self.feeds[feed_id].feed_site_link + "'") except: return self.error_page("Error") else: try: c.execute("UPDATE feeds SET mail=0 WHERE feed_site_link='" + - self.feeds[feed_id].feed_site_link.encode('utf-8') + "'") + self.feeds[feed_id].feed_site_link + "'") except: return self.error_page("Error") conn.commit() @@ -930,14 +903,10 @@ class Root: target="_blank">%s \n""" % \ - (feed.feed_id, \ - feed.feed_site_link.encode('utf-8'), \ - feed.feed_title.encode('utf-8'), \ - feed.feed_link.encode('utf-8'), \ - feed.feed_image.encode('utf-8')) + (feed.feed_id, feed.feed_site_link, feed.feed_title, feed.feed_link, feed.feed_image) # descrition for the CSS ToolTips - article_content = utils.clear_string(article.article_description.encode('utf-8')) + article_content = utils.clear_string(article.article_description) if article_content: description = " ".join(article_content[:500].split(' ')[:-1]) else: @@ -945,10 +914,9 @@ class Root: # a description line per article (date, title of the article and # CSS description tooltips on mouse over) - html += article.article_date.encode('utf-8') + " - " + \ + html += article.article_date + " - " + \ """%s%s
\n""" % \ - (feed.feed_id, article.article_id.encode('utf-8'), \ - article.article_title.encode('utf-8')[:150], description) + (feed.feed_id, article.article_id, article.article_title[:150], description) html += "
\n" html += htmlfooter return html @@ -994,7 +962,7 @@ class Root: if feed in self.feeds.values(): utils.remove_feed(feed.feed_link) html += """

All articles from the feed %s are now removed from the base.


""" % \ - (feed.feed_title.encode('utf-8'),) + (feed.feed_title,) else: return self.error_page("This feed do not exists.") html += """Back to the management page.
\n""" @@ -1062,10 +1030,10 @@ class Root: > - pyAggr3g470r RSS feed + pyAggr3g470r news http:// - Cedric Bonhomme feeds + pyAggr3g470r export %s %s feeds.cgi @@ -1076,7 +1044,7 @@ class Root: for rss_feed_id in self.feeds.keys(): if export_method != "export_RSS": folder = utils.path + "/var/export/" + \ - utils.normalize_filename(feed.feed_title.strip().encode("utf-8").replace(':', '').lower()) + utils.normalize_filename(feed.feed_title.strip().replace(':', '').lower()) try: os.makedirs(folder) except OSError: @@ -1091,8 +1059,8 @@ class Root: content = htmlheader() content += '\n
\n' content += """

%s


""" % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) - content += article.article_description.encode('utf-8') + (article.article_link, article.article_title) + content += article.article_description content += "
\n
\n" content += htmlfooter @@ -1103,8 +1071,8 @@ class Root: content = "" content += '\n
\n' content += """

%s


""" % \ - (article.article_link.encode('utf-8'), article.article_title.encode('utf-8')) - content += article.article_description.encode('utf-8') + (article.article_link, article.article_title) + content += article.article_description content += '
\n
Generated with pyAggr3g470r\n' # Export all articles in RSS format @@ -1116,8 +1084,8 @@ class Root: # Export all articles in raw text elif export_method == "export_TXT": - content = "Title: " + article.article_title.encode('utf-8') + "\n\n\n" - content += utils.clear_string(article.article_description.encode('utf-8')) + content = "Title: " + article.article_title + "\n\n\n" + content += utils.clear_string(article.article_description) name = os.path.normpath(folder + "/" + name + ".txt") if export_method != "export_RSS": with open(name, "w") as f: diff --git a/utils.py b/utils.py index d8d205ba..81366822 100755 --- a/utils.py +++ b/utils.py @@ -163,7 +163,7 @@ def top_words(feeds, n=10, size=5): wordre = re.compile(r'\b\w{%s,}\b' % size, re.I) for feed in feeds.values(): for article in feed.articles.values(): - for word in wordre.findall(clear_string(article.article_description.encode('utf-8'))): + for word in wordre.findall(clear_string(article.article_description)): words[word.lower()] += 1 return words.most_common(n) @@ -366,11 +366,11 @@ def load_feed(): # Current Feed object feed_object = articles.Feed() - feed_object.feed_id = feed_id - feed_object.feed_title = feed[0] - feed_object.feed_image = feed[3] - feed_object.feed_link = feed[2] - feed_object.feed_site_link = feed[1] + feed_object.feed_id = feed_id.encode('utf-8') + feed_object.feed_title = feed[0].encode('utf-8') + feed_object.feed_image = feed[3].encode('utf-8') + feed_object.feed_link = feed[2].encode('utf-8') + feed_object.feed_site_link = feed[1].encode('utf-8') feed_object.mail = feed[4] if list_of_articles != []: @@ -382,11 +382,11 @@ def load_feed(): # Current Article object article_object = articles.Article() - article_object.article_id = article_id - article_object.article_date = article[0] - article_object.article_title = unescape(article[1]) - article_object.article_link = article[2] - article_object.article_description = unescape(article[3]) + article_object.article_id = article_id.encode('utf-8') + article_object.article_date = article[0].encode('utf-8') + article_object.article_title = unescape(article[1]).encode('utf-8') + article_object.article_link = article[2].encode('utf-8') + article_object.article_description = unescape(article[3]).encode('utf-8') article_object.article_readed = article[4] article_object.like = article[6] -- cgit