d6ca3c66113d2f0bb6750106123e34c5ae5cb210
3 from feedcache
.cache
import Cache
5 from django
.template
.defaultfilters
import truncatewords_html
6 from django
.utils
.encoding
import smart_unicode
8 def TryEncoding(content
):
9 for body_charset
in 'UTF-8', 'US-ASCII', 'ISO-8859-1', :
11 return content
.encode(body_charset
)
15 if not type(content
) is str:
20 if hasattr(feed
, "content"):
21 return feed
.content
[0]["value"]
28 "http://planet.gentoo.org/atom.xml"
29 "http://overlays.gentoo.org/rss20.xml"
30 "http://www.gentoo.org/rdf/en/gentoo-news.rdf"
35 u'http://planet.gentoo.org/'
36 >>> for e in f: print e["title"], e["content"]
39 def __init__(self
, url
, summary
=False):
40 storage
= shelve
.open("/home/timemachine/.feedcache")
43 self
.feed
= fc
.fetch(url
)
45 self
.summary
= summary
49 return self
.feed
.feed
.title
52 return self
.feed
.feed
.link
55 if self
.iterator
>= len(self
.feed
.entries
): raise StopIteration
57 entry
= self
.feed
.entries
[self
.iterator
]
59 title
= TryEncoding(entry
["title"])
60 content
= TryEncoding(GetContent(entry
))
64 content
= TryEncoding(truncatewords_html(content
, 30))
65 content
= "".join((content
, "..."))
67 entry
= dict((("title", title
), ("content", content
), ("link", link
)))
77 import doctest, ebuilds.ebuildfind.planet as planet
78 return doctest.testmod(planet)
80 "http://news.google.fr/news?pz=1&ned=us&hl=en&q=gentoo+AND+(linux+OR+OS+OR+Operating+System+OR+GNU)&output=rss"
81 "http://www.gentoo.org/rdf/en/gentoo-news.rdf"
82 "http://planet.gentoo.org/atom.xml"
83 "http://overlays.gentoo.org/rss20.xml"
86 f
= Parser("http://planet.gentoo.org/atom.xml", True)
96 if __name__
== "__main__":