# HG changeset patch # User Paul Boddie # Date 1342478474 -7200 # Node ID 8e9825a38cdb1206224fb763f27645ddb5f043ec # Parent eee0ea142168d3f341afae6481529f268f8604e3 Introduced feed downloading and caching using MoinRemoteSupport. diff -r eee0ea142168 -r 8e9825a38cdb macros/SharedContent.py --- a/macros/SharedContent.py Tue Jul 17 00:03:35 2012 +0200 +++ b/macros/SharedContent.py Tue Jul 17 00:41:14 2012 +0200 @@ -7,9 +7,14 @@ """ from MoinMoin.Page import Page -import urllib +from MoinRemoteSupport import * import xml.dom.pulldom +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO + Dependencies = ["time"] MAX_ENTRIES = 5 @@ -41,9 +46,16 @@ except IndexError: pass - # Obtain the feed. + # Obtain the resource, using a cached version if appropriate. - feed = urllib.urlopen(feed_url) + max_cache_age = int(getattr(request.cfg, "moin_share_max_cache_age", "300")) + data = getCachedResource(request, feed_url, "MoinShare", "wiki", max_cache_age) + if not data: + return fmt.text(_("SharedContent: updates could not be retrieved for %s") % feed_url) + + feed = StringIO(data) + _url = feed.readline() + _content_type = feed.readline() try: # Parse each node from the feed.