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). --- utils.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'utils.py') 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. -- cgit