aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-06-09 13:38:16 +0200
committercedricbonhomme <devnull@localhost>2010-06-09 13:38:16 +0200
commitc79327b13344e6ab150cd46062def77cf839bf86 (patch)
treef6cd6e1f26d11a84bfd4ce9cda7666630630bbd9 /utils.py
parentMinor bug fix. (diff)
downloadnewspipe-c79327b13344e6ab150cd46062def77cf839bf86.tar.gz
newspipe-c79327b13344e6ab150cd46062def77cf839bf86.tar.bz2
newspipe-c79327b13344e6ab150cd46062def77cf839bf86.zip
It is now possible to add a feed just with the URL of the web page via the management page. The URL of the feed is obtained by parsing the web page with the module BeautifulSoup. There is therefore no need to edit the file feed.lst by hand.
Diffstat (limited to 'utils.py')
-rwxr-xr-xutils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index b5e357d9..ea04fb12 100755
--- a/utils.py
+++ b/utils.py
@@ -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.
bgstack15