From f34d5bf48f08c75f7dc4476d197735f41219889b Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Sun, 19 Jun 2011 00:10:54 +0200 Subject: Added a new function which enables to change the URL of a feed (this updates all the data base). --- pyAggr3g470r.py | 14 +++++++++----- utils.py | 25 +++++++++++++++++++++++++ var/feed.lst | 4 ++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 51915d0a..a5ed2d4a 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -635,6 +635,11 @@ class Root: html += article.article_date + " - " + \ """%s%s
\n""" % \ (feed.feed_id, article.article_id, article.article_title[:150], description) + + + html += """\n

\n
\n""" % \ + (feed.feed_link,) + dic = {} dic[feed.feed_id] = self.feeds[feed.feed_id] top_words = utils.top_words(dic, n=50, size=int(word_size)) @@ -648,9 +653,6 @@ class Root: utils.tag_cloud(top_words) + '' html += "
" - #html += """
\n
\n""" % (feed.feed_id,) - - html += "
" html += htmlfooter return html @@ -1096,14 +1098,16 @@ class Root: remove_feed.exposed = True - def change_feed_url(self, querrystring): + def change_feed_url(self, new_feed_url, old_feed_url): """ Enables to change the URL of a feed already present in the database. """ html = htmlheader() html += htmlnav html += """
""" - + print cherrypy.request.params + utils.change_feed_url(old_feed_url, new_feed_url) + html += "

The URL of the feed has been changed.

" html += "
\n" html += htmlfooter return html diff --git a/utils.py b/utils.py index 29ca43d3..c31b24f4 100755 --- a/utils.py +++ b/utils.py @@ -253,6 +253,31 @@ def add_feed(feed_url): f.write(feed_url + "\n") return True +def change_feed_url(old_feed_url, new_feed_url): + """ + Change the URL of a feed. + """ + # Replace the URL in the text file + with open("./var/feed.lst", "r") as f: + lines = f.readlines() + try: + lines[lines.index(old_feed_url+"\n")] = new_feed_url + '\n' + except: + return + with open("./var/feed.lst", "w") as f: + f.write("\n".join(lines)) + + # Replace the URL in the data base. + try: + conn = sqlite3.connect(sqlite_base, isolation_level = None) + c = conn.cursor() + c.execute("UPDATE articles SET feed_link='" + new_feed_url + "' WHERE feed_link='" + old_feed_url +"'") + c.execute("UPDATE feeds SET feed_link='" + new_feed_url + "' WHERE feed_link='" + old_feed_url +"'") + conn.commit() + c.close() + except Exception, e: + print e + def remove_feed(feed_url): """ Remove a feed from the file feed.lst and from the SQLite base. diff --git a/var/feed.lst b/var/feed.lst index 5678f144..0b373515 100755 --- a/var/feed.lst +++ b/var/feed.lst @@ -4,7 +4,7 @@ http://blog.cedricbonhomme.org/feed/ http://bnjgat.fr/weblog/?feed/rss2 http://standblog.org/blog/feed/atom http://www.haypocalc.com/blog/rss.php -http://linuxfr.org/backend/news-homepage/rss20.rss +http://linuxfr.org/news.atom http://rss.slashdot.org/Slashdot/slashdot http://theinvisiblethings.blogspot.com/feeds/posts/default http://torvalds-family.blogspot.com/feeds/posts/default @@ -24,7 +24,7 @@ http://www.laquadrature.net/en/rss.xml http://static.fsf.org/fsforg/rss/blogs.xml http://esr.ibiblio.org/?feed=rss2 http://www.maitre-eolas.fr/feed/atom -http://linuxfr.org/backend/journaux/rss20.rss +http://linuxfr.org/journaux.atom http://www.le-tigre.net/spip.php?page=backend http://www.schneier.com/blog/index.rdf http://www.handcrafted-games.com/index.php?feed/atom -- cgit