psa: adding missing opml_lib library
authorYves Marcoz <yves@marcoz.org>
Tue, 24 Jan 2012 05:58:02 +0000 (21:58 -0800)
committerYves Marcoz <yves@marcoz.org>
Tue, 24 Jan 2012 05:58:02 +0000 (21:58 -0800)
psa_harmattan/feedingit/pysrc/opml_lib.py [new file with mode: 0644]

diff --git a/psa_harmattan/feedingit/pysrc/opml_lib.py b/psa_harmattan/feedingit/pysrc/opml_lib.py
new file mode 100644 (file)
index 0000000..4de756b
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/env python2.5
+
+# 
+# Copyright (c) 2007-2008 INdT.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public License
+#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# ============================================================================
+# Name        : FeedingIt.py
+# Author      : Yves Marcoz
+# Version     : 0.2.2
+# Description : Simple RSS Reader
+# ============================================================================
+
+from xml.dom.minidom import parse, parseString
+import time
+from os.path import isfile, dirname
+import logging
+logger = logging.getLogger(__name__)
+
+def getOpmlText(listing):
+    time_now = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
+    opml_text = """<?xml version="1.0" encoding="UTF-8"?>
+<opml version="1.0">
+<head>
+    <title>Feeding It Export</title>
+</head>
+<body>
+"""
+    for key in listing.getListOfFeeds():
+        title = listing.getFeedTitle(key)
+        url = listing.getFeedUrl(key)
+        if not title == "Archived Articles": 
+            opml_text += """\n\t\t<outline  type="rss" text="%s" title="%s" xmlUrl="%s"/>""" % (sanitize(title), sanitize(title), sanitize(url))
+    opml_text += """\n</body>\n</opml>\n"""
+    return opml_text
+    
+def sanitize(text):
+    from cgi import escape
+    return escape(text).encode('ascii', 'xmlcharrefreplace')
+        
+def parseOpml(opmlData):
+    feeds = []
+    dom1 = parseString(opmlData)
+
+    outlines = dom1.getElementsByTagName('outline')
+    for outline in outlines:
+        title = outline.getAttribute('text')
+        url = outline.getAttribute('xmlUrl')
+        if url == "":
+            url = outline.getAttribute('htmlUrl')
+        if not url == "":
+            feeds.append( (title, url) )
+    return feeds
\ No newline at end of file