aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-07-23 10:58:17 +0200
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-07-23 10:58:17 +0200
commit0b9b9c390edb520d1a7a63996aba5868f9a69ad6 (patch)
treeb2fe9b3549face4303a30a93720ebc9944043972
parentImproved the function which add a new feed URL to the file with the list of m... (diff)
downloadnewspipe-0b9b9c390edb520d1a7a63996aba5868f9a69ad6.tar.gz
newspipe-0b9b9c390edb520d1a7a63996aba5868f9a69ad6.tar.bz2
newspipe-0b9b9c390edb520d1a7a63996aba5868f9a69ad6.zip
Improved add_feed
-rwxr-xr-xsource/utils.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/source/utils.py b/source/utils.py
index ddcb2e55..90184020 100755
--- a/source/utils.py
+++ b/source/utils.py
@@ -206,16 +206,14 @@ def add_feed(feed_url):
"""
Add the URL feed_url in the file feed.lst.
"""
- feeds = []
- if os.path.exists(conf.FEED_LIST):
- for line in open(conf.FEED_LIST, "r"):
- feeds.append(line.replace("\n", ""))
- if feed_url in line:
- # if the feed is already in the file
- return False
- feeds.append(feed_url)
+ with open(conf.FEED_LIST, "r") as f:
+ lines = f.readlines()
+ lines = list(map(str.strip, lines))
+ if feed_url in lines:
+ return False
+ lines.append(feed_url)
with open(conf.FEED_LIST, "w") as f:
- f.write("\n".join(feeds) + "\n")
+ f.write("\n".join(lines))
return True
def change_feed_url(old_feed_url, new_feed_url):
@@ -245,7 +243,7 @@ def remove_feed(feed_url):
if feed_url not in line:
feeds.append(line.replace("\n", ""))
with open(conf.FEED_LIST, "w") as f:
- f.write("\n".join(feeds) + "\n")
+ f.write("\n".join(feeds))
def search_feed(url):
"""
bgstack15