diff options
-rwxr-xr-x | pyAggr3g470r.py | 21 | ||||
-rwxr-xr-x | 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 += "<h1>Delete Feeds</h1>\n" - html += """<form method=get action="del_feed/"><select name="feed_list">\n""" + html += """<form method=get action="/remove_feed/"><select name="url">\n""" for feed_id in self.articles.keys(): html += """\t<option value="%s">%s</option>\n""" % \ (feed_id, self.feeds[feed_id][3].encode('utf-8')) - html += """</select></form>\n""" + html += """</select><input type="submit" value="OK"></form>\n""" html += """<p>Active e-mail notifications: <a href="/list_notification">%s</a></p>\n""" % \ (len([feed for feed in self.feeds.values() if feed[6] == "1"]),) html += """<p>You like <a href="/list_favorites/">%s</a> article(s).</p>\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 += """<div class="left inner">""" + utils.remove_feed(self.feeds[url][4]) + html+= """<p>All articles from this feed are removed from the base.</p><br />""" + html += """<a href="/management/">Back to the management page.</a><br />\n""" + html += "<hr />\n" + html += htmlfooter + return html + + remove_feed.exposed = True + + def export(self, export_method): """ Export articles stored in the SQLite database in text files. @@ -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'] |