From a3672bb2705189281cbb062b2455412a56898c72 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 24 Jul 2013 08:45:39 +0200 Subject: Improved remove_feed function. --- source/utils.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source') diff --git a/source/utils.py b/source/utils.py index 90184020..3f945a87 100755 --- a/source/utils.py +++ b/source/utils.py @@ -236,14 +236,16 @@ def remove_feed(feed_url): """ Remove a feed from the file feed.lst and from the SQLite base. """ - feeds = [] - # Remove the URL from the file feed.lst - if os.path.exists(conf.FEED_LIST): - for line in open(conf.FEED_LIST, "r"): - if feed_url not in line: - feeds.append(line.replace("\n", "")) - with open(conf.FEED_LIST, "w") as f: - f.write("\n".join(feeds)) + with open(conf.FEED_LIST, "r") as f: + lines = f.readlines() + lines = list(map(str.strip, lines)) + try: + del lines[lines.index(feed_url)] + except: + return False + with open(conf.FEED_LIST, "w") as f: + f.write("\n".join(lines)) + return True def search_feed(url): """ -- cgit