diff options
author | cedricbonhomme <devnull@localhost> | 2010-04-15 13:15:05 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-04-15 13:15:05 +0200 |
commit | a8fe3cf2ac934f4fe3e9264d9a3e3ee6ac5131bf (patch) | |
tree | 8c3dfa9644d77f039a297dd2d5099feea068f551 | |
parent | Introduction of a Google Buzz button to pyAggr3g470r. (diff) | |
download | newspipe-a8fe3cf2ac934f4fe3e9264d9a3e3ee6ac5131bf.tar.gz newspipe-a8fe3cf2ac934f4fe3e9264d9a3e3ee6ac5131bf.tar.bz2 newspipe-a8fe3cf2ac934f4fe3e9264d9a3e3ee6ac5131bf.zip |
Mark or unmark an article as favorites.
-rwxr-xr-x | feedgetter.py | 5 | ||||
-rwxr-xr-x | pyAggr3g470r.py | 71 | ||||
-rwxr-xr-x | utils.py | 6 |
3 files changed, 77 insertions, 5 deletions
diff --git a/feedgetter.py b/feedgetter.py index 278cc58d..2fb43bc5 100755 --- a/feedgetter.py +++ b/feedgetter.py @@ -115,13 +115,14 @@ class FeedGetter(object): description = "" try: - self.c.execute('insert into articles values (?,?,?,?,?,?)', (\ + self.c.execute('insert into articles values (?,?,?,?,?,?,?)', (\ datetime(*article.updated_parsed[:6]), \ utils.remove_html_tags(article.title.encode('utf-8')), \ article.link.encode('utf-8'), \ description, \ "0", \ - feed_link)) + feed_link, \ + "0")) result = self.c.execute("SELECT mail from feeds WHERE feed_site_link='" + \ a_feed.feed.link.encode('utf-8') + "'").fetchall() if result[0][0] == "1": diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index ab8ac2a7..f0a2182a 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -38,6 +38,10 @@ path = {'/css/style.css': {'tools.staticfile.on': True, \ 'tools.staticfile.filename':utils.path+'css/img/blogmarks.png'}, \ '/css/img/buzz.png': {'tools.staticfile.on': True, \ 'tools.staticfile.filename':utils.path+'css/img/buzz.png'}, \ + '/css/img/heart.png': {'tools.staticfile.on': True, \ + 'tools.staticfile.filename':utils.path+'css/img/heart.png'}, \ + '/css/img/heart_open.png': {'tools.staticfile.on': True, \ + 'tools.staticfile.filename':utils.path+'css/img/heart_open.png'}, \ '/var/histogram.png':{'tools.staticfile.on': True, \ 'tools.staticfile.filename':utils.path+'var/histogram.png'}} @@ -173,6 +177,8 @@ class Root: (feed_id, self.feeds[feed_id][3].encode('utf-8')) html += """</select></form>\n""" html += """<p><a href="/list_notification">Active e-mail notifications</a></p>\n""" + html += """<p>You like <a href="/list_like/">%s</a> article(s).</p>\n""" % \ + sum([len([article for article in self.articles[feed_id] if article[7]=="1"]) for feed_id in self.feeds.keys()]) html += "<hr />\n" html += """<p>The database contains a total of %s article(s) with @@ -326,6 +332,13 @@ class Root: html += """<h1><i>%s</i> from <a href="/all_articles/%s">%s</a></h1>\n<br />\n""" % \ (article[2].encode('utf-8'), feed_id, \ self.feeds[feed_id][3].encode('utf-8')) + if article[7] == "1": + html += """<a href="/like/no:%s:%s"><img src="/css/img/heart.png" title="I like this article!" /></a>""" % \ + (feed_id, article_id) + else: + html += """<a href="/like/yes:%s:%s"><img src="/css/img/heart_open.png" title="Click if you like this article." /></a>""" % \ + (feed_id, article_id) + html += "<br /><br />" description = article[4].encode('utf-8') if description: html += description @@ -632,6 +645,64 @@ class Root: mail_notification.exposed = True + def like(self, param): + """ + Mark or unmark an article as favorites. + """ + try: + action, feed_id, article_id = param.split(':') + except: + return self.error_page("Bad URL") + try: + articles_list = self.articles[feed_id] + except KeyError: + return self.error_page("This feed do not exists.") + for article in articles_list: + if article_id == article[0]: + try: + conn = sqlite3.connect(utils.sqlite_base, isolation_level = None) + c = conn.cursor() + # Mark all articles as read. + if action == "yes": + c.execute("UPDATE articles SET like=1 WHERE article_link='" + \ + article[3] + "'") + if action == "no": + c.execute("UPDATE articles SET like=0 WHERE article_link='" + \ + article[3] + "'") + conn.commit() + c.close() + except Exception: + self.error_page("Impossible to like/dislike this article (database error).") + break + return self.description(feed_id+":"+article_id) + + like.exposed = True + + + def list_like(self): + """ + List of favorites articles + """ + html = htmlheader + html += htmlnav + html += """<div class="left inner">""" + html += "<h1>Your favorites articles</h1>" + for rss_feed_id in self.feeds.keys(): + for article in self.articles[rss_feed_id]: + if article[7] == "1": + html += article[1].encode('utf-8') + \ + """ - <a href="/description/%s:%s" rel="noreferrer" target="_blank">%s</a> + from <i><a href="%s">%s</a></i><br />\n""" % \ + (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')) + html += "<hr />\n" + html += htmlfooter + return html + + list_like.exposed = True + + def update(self, path=None, event = None): """ Synchronizes transient objects with the database, @@ -185,7 +185,7 @@ def create_base(): c.execute('''create table if not exists articles (article_date text, article_title text, \ article_link text PRIMARY KEY, article_description text, \ - article_readed text, feed_link text)''') + article_readed text, feed_link text, like text)''') conn.commit() c.close() @@ -205,7 +205,7 @@ def load_feed(): # articles[feed_id] = (article_id, article_date, article_title, # article_link, article_description, article_readed, - # article_language) + # article_language, like) # feeds[feed_id] = (nb_article, nb_article_unreaded, feed_image, # feed_title, feed_link, feed_site_link, mail) articles, feeds = {}, {} @@ -233,7 +233,7 @@ def load_feed(): language = "IMPORT_ERROR" article_list = [article_id, article[0], article[1], \ - article[2], article[3], article[4], language] + article[2], article[3], article[4], language, article[6]] if feed_id not in articles: articles[feed_id] = [article_list] |