Changeset 1656
- Timestamp:
- 07/07/08 13:39:57 (5 months ago)
- Location:
- trunk/pylucid
- Files:
-
- 1 added
- 3 modified
-
media/PyLucid/internal_page/RSS/RSS.html (modified) (1 diff)
-
PyLucid/plugins_internal/RSS/RSS.py (modified) (4 diffs)
-
PyLucid/plugins_internal/RSS/RSS_cfg.py (modified) (1 diff)
-
PyLucid/tools/feedparser.py (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/media/PyLucid/internal_page/RSS/RSS.html
r1449 r1656 1 1 <fieldset> 2 {% if title %}<legend><a href="{{ url }}">{{ title }}</a></legend>{% endif %} 2 <legend><a href="{{ url }}">{{ feed.feed.title }}</a></legend> 3 3 <ul> 4 {% for entry in entries %}4 {% for entry in feed.entries %} 5 5 <li> 6 <h1><a href="{{ entry.title_ link }}">{{ entry.title|escape }}</a></h1>6 <h1><a href="{{ entry.title_detail.base }}">{{ entry.title|safe }}</a></h1> 7 7 <p> 8 {% if entry.date %} 9 {{ entry.date }} 10 <br /> 11 {% endif %} 12 {{ entry.description }} 8 {{ entry.updated }}<br /> 9 {{ entry.summary|safe }} 13 10 </p> 14 11 </li> -
trunk/pylucid/PyLucid/plugins_internal/RSS/RSS.py
r1634 r1656 2 2 3 3 """ 4 PyLucid Plugin 5 Blendet RSS-Daten von einem anderen Server in die CMS-Seite ein. 6 Bsp.: 7 <lucidFunction:RSS>http://sourceforge.net/export/rss2_projnews.php?group_id=146328</lucidFunction> 4 PyLucid RSS plugin 5 ~~~~~~~~~~~~~~~~~~ 8 6 9 Last commit info: 10 ---------------------------------- 11 $LastChangedDate$ 12 $Rev$ 13 $Author$ 7 Include external RSS Feeds directly into a CMS page. 8 Used feedparser by Mark Pilgrim: http://feedparser.org 9 http://feedparser.googlecode.com/svn/trunk/LICENSE 14 10 15 Created by Jens Diemer 11 Last commit info: 12 ~~~~~~~~~~~~~~~~~ 13 $LastChangedDate$ 14 $Rev$ 15 $Author$ 16 16 17 license: 18 GNU General Public License v2 or above 19 http://www.opensource.org/licenses/gpl-license.php 20 17 :copyleft: 2007 by the PyLucid team, see AUTHORS for more details. 18 :license: GNU GPL v3 or above, see LICENSE for more details. 21 19 """ 22 20 23 21 __version__= "$Rev$" 24 22 25 import xml.dom.minidom 26 import md5, sys, os, urllib, time 23 import time 27 24 28 25 import socket … … 34 31 35 32 from PyLucid.system.BasePlugin import PyLucidBasePlugin 36 from PyLucid.system.response import SimpleStringIO 33 from PyLucid.tools import feedparser 34 37 35 from django.core.cache import cache 38 39 36 from django.utils.safestring import mark_safe 40 37 41 38 class RSS(PyLucidBasePlugin): 42 39 43 info_txt = '<small class="RSS_info">\n\t%s\n</small>\n' 40 def _debug(self, url, feed): 41 from pprint import pformat 42 self.response.write("<h2>RSS debug for '%s':</h2>\n" % url) 43 self.response.write("<pre>\n") 44 self.response.write(pformat(feed)) 45 self.response.write("</pre>\n") 44 46 45 def lucidTag(self, url, title=None): 46 47 def lucidTag(self, url, debug=False, title=None): 47 48 # rss_page = cache.get(url) 48 49 # if rss_page: … … 54 55 55 56 try: 56 rss_data = urllib.urlopen(url)57 feed = feedparser.parse(url) 57 58 except Exception, e: 58 59 self.response.write( … … 63 64 # cache.set(url, rss_page) 64 65 65 server_response= time.time() - start_time66 duration = time.time() - start_time 66 67 67 start_time = time.time() 68 r = RSS_Maker() 69 data = r.feed(rss_data) 70 paser_duration = time.time() - start_time 68 if debug: 69 self._debug(url, feed) 71 70 72 71 context = { 73 72 "url": url, 74 "title": title, 75 "entries": data, 76 "server_response": server_response, 77 "paser_duration": paser_duration, 73 "feed": feed, 74 "duration": duration, 78 75 } 79 76 self._render_template("RSS", context)#, debug=True) 80 77 81 82 #_____________________________________________________________________________83 84 DEFAULT_NAMESPACES = (85 None, # RSS 0.91, 0.92, 0.93, 0.94, 2.086 'http://purl.org/rss/1.0/', # RSS 1.087 'http://my.netscape.com/rdf/simple/0.9/' # RSS 0.9088 )89 DUBLIN_CORE = ('http://purl.org/dc/elements/1.1/',)90 91 class RSS_Maker(object):92 93 def feed(self, rss_data):94 """95 Diese Funktion wird direkt vom Modul-Manager ausgeführt.96 """97 rssDocument = xml.dom.minidom.parse(rss_data)98 99 entries = []100 for node in self.getElementsByTagName(rssDocument, 'item'):101 entry_data = {102 "title_link": self.get_txt(node, "link", "#"),103 "title": self.get_txt(node, "title", None),104 "date": self.get_txt(node, "date", None),105 "description": self.get_txt(node, "description", None),106 }107 entries.append(entry_data)108 return entries109 110 111 def getElementsByTagName(self, node, tagName,112 possibleNamespaces=DEFAULT_NAMESPACES113 ):114 for namespace in possibleNamespaces:115 children = node.getElementsByTagNameNS(namespace, tagName)116 if len(children): return children117 return []118 119 def node_data( self, node, tagName,120 possibleNamespaces=DEFAULT_NAMESPACES121 ):122 children = self.getElementsByTagName(node, tagName, possibleNamespaces)123 node = len(children) and children[0] or None124 return node and "".join(125 [child.data.encode("utf_8") for child in node.childNodes]126 ) or None127 128 def get_txt(self, node, tagName, default_txt=""):129 """130 Liefert den Inhalt >tagName< des >node< zurück, ist dieser nicht131 vorhanden, wird >default_txt< zurück gegeben.132 """133 return self.node_data(node, tagName) or self.node_data(134 node, tagName, DUBLIN_CORE135 ) or default_txt136 137 -
trunk/pylucid/PyLucid/plugins_internal/RSS/RSS_cfg.py
r1634 r1656 16 16 17 17 plugin_manager_data = { 18 "debug" : { 19 "must_login" : True, 20 "must_admin" : False, 21 }, 18 22 "lucidTag" : { 19 23 "must_login" : False, 20 24 "must_admin" : False, 21 } 25 }, 22 26 }
