diff options
-rwxr-xr-x | pyAggr3g470r.py | 30 | ||||
-rwxr-xr-x | utils.py | 26 |
2 files changed, 54 insertions, 2 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 00987cda..4145bc99 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -182,8 +182,8 @@ class Root: html += htmlnav html += """<div class="left inner">\n""" html += "<h1>Add Feeds</h1>\n" - html += """<form method=get action="add_feed/"><input type="text" name="v" value="">\n<input - type="submit" value="OK"></form>\n""" + html += """<form method=get action="/add_feed/"><input type="text" name="url" value="">\n<input + type="submit" value="OKi"></form>\n""" if self.articles: html += "<h1>Delete Feeds</h1>\n" @@ -747,6 +747,32 @@ class Root: list_favorites.exposed = True + def add_feed(self, url): + """ + Add a new feed with the URL of a page. + """ + html = htmlheader + html += htmlnav + html += """<div class="left inner">""" + # search the feed in the HTML page with BeautifulSoup + feed_url = utils.search_feed(url) + # if a feed exists + if feed_url is not None: + result = utils.add_feed(feed_url) + # if the feed is not already in the file feed.lst + if result is False: + html += "<p>You are already following this feed!</p>" + else: + html += """<p>Feed added. You can now <a href="/fetch/">fetch your feeds</a>.</p>""" + html += "<br />" + html += """<a href="/management/">Back to the management page.</a><br />\n""" + html += "<hr />\n" + html += htmlfooter + return html + + add_feed.exposed = True + + def export(self, export_method): """ Export articles stored in the SQLite database in text files. @@ -1,6 +1,8 @@ #! /usr/local/bin/python #-*- coding: utf-8 -*- +from __future__ import with_statement + __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.6 $" __date__ = "$Date: 2010/04/29 $" @@ -22,6 +24,9 @@ import operator import smtplib from email.mime.text import MIMEText +import urllib2 +from BeautifulSoup import BeautifulSoup + from datetime import datetime from string import punctuation from collections import defaultdict @@ -186,6 +191,27 @@ def compare(stringtime1, stringtime2): return 1 return 0 +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: + return False + with open("./var/feed.lst", "a") as f: + f.write(feed_url + "\n") + return True + +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'): + return feed_link['href'] + return None + def create_base(): """ Create the base if not exists. |