From e6bbb708cde59b3f32b69e50f6312652332f3a83 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Thu, 10 Jun 2010 09:12:54 +0200 Subject: Remove a feed from the file feed.lst. Some improvements. --- pyAggr3g470r.py | 21 +++++++++++++++++++-- utils.py | 26 +++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 85b3cee1..c5eb9b6a 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -187,11 +187,11 @@ class Root: if self.articles: html += "

Delete Feeds

\n" - html += """
\n""" for feed_id in self.articles.keys(): html += """\t\n""" % \ (feed_id, self.feeds[feed_id][3].encode('utf-8')) - html += """
\n""" + html += """\n""" html += """

Active e-mail notifications: %s

\n""" % \ (len([feed for feed in self.feeds.values() if feed[6] == "1"]),) html += """

You like %s article(s).

\n""" % \ @@ -773,6 +773,23 @@ class Root: add_feed.exposed = True + def remove_feed(self, url): + """ + Remove a feed from the file fee.lst. + """ + html = htmlheader + html += htmlnav + html += """
""" + utils.remove_feed(self.feeds[url][4]) + html+= """

All articles from this feed are removed from the base.


""" + html += """Back to the management page.
\n""" + html += "
\n" + html += htmlfooter + return html + + remove_feed.exposed = True + + def export(self, export_method): """ Export articles stored in the SQLite database in text files. diff --git a/utils.py b/utils.py index a23584e0..38e077b2 100755 --- a/utils.py +++ b/utils.py @@ -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'] -- cgit