diff options
author | cedricbonhomme <devnull@localhost> | 2010-06-10 09:12:54 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-06-10 09:12:54 +0200 |
commit | e6bbb708cde59b3f32b69e50f6312652332f3a83 (patch) | |
tree | 786593b6a74313141329f41dd73d87b39d5aac81 /utils.py | |
parent | Removed xkcd (diff) | |
download | newspipe-e6bbb708cde59b3f32b69e50f6312652332f3a83.tar.gz newspipe-e6bbb708cde59b3f32b69e50f6312652332f3a83.tar.bz2 newspipe-e6bbb708cde59b3f32b69e50f6312652332f3a83.zip |
Remove a feed from the file feed.lst. Some improvements.
Diffstat (limited to 'utils.py')
-rwxr-xr-x | utils.py | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -196,20 +196,40 @@ def add_feed(feed_url): """ Add the URL feed_url in the file feed.lst. """ - for ligne in open("./var/feed.lst", "r"): - if feed_url in ligne: + for line in open("./var/feed.lst", "r"): + if feed_url in line: return False with open("./var/feed.lst", "a") as f: f.write(feed_url + "\n") return True +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 + for line in open("./var/feed.lst", "r"): + if feed_url not in line: + feeds.append(line.replace("\n", "")) + with open("./var/feed.lst", "w") as f: + f.write("\n".join(feeds)) + # Remove articles from this feed from the SQLite base. + conn = sqlite3.connect(sqlite_base, isolation_level = None) + c = conn.cursor() + c.execute("") + conn.commit() + c.close() + def search_feed(url): """ Search a feed in a HTML page. """ page = urllib2.urlopen(url) soup = BeautifulSoup(page) - for feed_link in soup('link', type='application/atom+xml'): + feed_links = soup('link', type='application/atom+xml') + feed_links.append(soup('link', type='application/rss+xml')) + for feed_link in feed_links: if url not in feed_link['href']: return urlparse.urljoin(url, feed_link['href']) return feed_link['href'] |