3 from feedcache
.cache
import Cache
5 from django
.conf
import settings
7 from django
.template
.defaultfilters
import truncatewords_html
10 def TryEncoding(content
):
11 for body_charset
in 'UTF-8', 'US-ASCII', 'ISO-8859-1', :
13 return content
.encode(body_charset
)
17 if not type(content
) is str:
21 if hasattr(feed
, "content"):
22 return feed
.content
[0]["value"]
28 "http://planet.gentoo.org/atom.xml"
29 "http://overlays.gentoo.org/rss20.xml"
30 >>> f = Parser("http://www.gentoo.org/rdf/en/gentoo-news.rdf")
34 u'http://planet.gentoo.org/'
35 >>> for e in f: print e["title"], e["content"]
38 def __init__(self
, url
, summary
=False):
39 storage
= shelve
.open(settings
.ROOT_PATH
+ "feedcache")
42 self
.feed
= fc
.fetch(url
)
44 self
.summary
= summary
48 return self
.feed
.feed
.title
51 return self
.feed
.feed
.link
54 if self
.iterator
>= len(self
.feed
.entries
): raise StopIteration
56 entry
= self
.feed
.entries
[self
.iterator
]
58 title
= TryEncoding(entry
["title"])
59 content
= TryEncoding(GetContent(entry
))
63 content
= TryEncoding(truncatewords_html(content
, 30))
64 content
= "".join((content
, "..."))
66 entry
= dict((("title", title
), ("content", content
), ("link", link
)))