psa: added progress bar for updates
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / pysrc / opml_lib.py
1 #!/usr/bin/env python2.5
2
3
4 # Copyright (c) 2007-2008 INdT.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public License
16 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 # ============================================================================
20 # Name        : FeedingIt.py
21 # Author      : Yves Marcoz
22 # Version     : 0.2.2
23 # Description : Simple RSS Reader
24 # ============================================================================
25
26 from xml.dom.minidom import parse, parseString
27 import time
28 from os.path import isfile, dirname
29 import logging
30 logger = logging.getLogger(__name__)
31
32 def getOpmlText(listing):
33     time_now = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
34     opml_text = """<?xml version="1.0" encoding="UTF-8"?>
35 <opml version="1.0">
36 <head>
37     <title>Feeding It Export</title>
38 </head>
39 <body>
40 """
41     for key in listing.getListOfFeeds():
42         title = listing.getFeedTitle(key)
43         url = listing.getFeedUrl(key)
44         if not title == "Archived Articles": 
45             opml_text += """\n\t\t<outline  type="rss" text="%s" title="%s" xmlUrl="%s"/>""" % (sanitize(title), sanitize(title), sanitize(url))
46     opml_text += """\n</body>\n</opml>\n"""
47     return opml_text
48     
49 def sanitize(text):
50     from cgi import escape
51     return escape(text).encode('ascii', 'xmlcharrefreplace')
52         
53 def parseOpml(opmlData):
54     feeds = []
55     dom1 = parseString(opmlData)
56
57     outlines = dom1.getElementsByTagName('outline')
58     for outline in outlines:
59         title = outline.getAttribute('text')
60         url = outline.getAttribute('xmlUrl')
61         if url == "":
62             url = outline.getAttribute('htmlUrl')
63         if not url == "":
64             feeds.append( (title, url) )
65     return feeds