6c9abd5b7ba0630ac382170bd0105e77f2578cf2
3 from feedcache
.cache
import Cache
7 from django
.template
.defaultfilters
import truncatewords_html
8 from django
.utils
.encoding
import smart_unicode
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:
22 if hasattr(feed
, "content"):
23 return feed
.content
[0]["value"]
30 "http://planet.gentoo.org/atom.xml"
31 "http://overlays.gentoo.org/rss20.xml"
32 "http://www.gentoo.org/rdf/en/gentoo-news.rdf"
37 u'http://planet.gentoo.org/'
38 >>> for e in f: print e["title"], e["content"]
41 def __init__(self
, url
, summary
=False):
42 storage
= shelve
.open(".feedcache")
45 self
.feed
= fc
.fetch(url
)
47 self
.summary
= summary
51 return self
.feed
.feed
.title
54 return self
.feed
.feed
.link
57 if self
.iterator
>= len(self
.feed
.entries
): raise StopIteration
59 entry
= self
.feed
.entries
[self
.iterator
]
61 title
= TryEncoding(entry
["title"])
62 content
= TryEncoding(GetContent(entry
))
66 content
= TryEncoding(truncatewords_html(content
, 30))
67 content
= "".join((content
, "..."))
69 entry
= dict((("title", title
), ("content", content
), ("link", link
)))
79 import doctest, ebuilds.ebuildfind.planet as planet
80 return doctest.testmod(planet)
82 "http://news.google.fr/news?pz=1&ned=us&hl=en&q=gentoo+AND+(linux+OR+OS+OR+Operating+System+OR+GNU)&output=rss"
83 "http://www.gentoo.org/rdf/en/gentoo-news.rdf"
84 "http://planet.gentoo.org/atom.xml"
85 "http://overlays.gentoo.org/rss20.xml"
88 f
= Parser("http://planet.gentoo.org/atom.xml", True)
98 if __name__
== "__main__":