I'm trying to merge RSS feeds using python and then play them back out to a website. Having researched the recommended methods I've opted for the following code which is basically a straight copy of what is recommended:
hit_list = ['http://www.bbc.co.uk/sport/football/teams/cardiff-city/rss.xml','http://www1.skysports.com/feeds/11704/news.xml','http://www.cardiffcity-mad.co.uk/rssfeeds/rssfull.asp']
# pull down all feeds
future_calls = [Future(feedparser.parse,rss_url) for rss_url in hit_list]
# block until they are all in
feeds = [future_obj() for future_obj in future_calls]
#Now that you have your feeds, extract all the entries
entries = []
for feed in feeds:
entries.extend(feed["items"])
values['feeds'] = sorted(entries, key=lambda entry: entry["updated_parsed"]
Later, I call the web using:
template = jinja_environment.get_template('TeamView.html')
self.response.out.write(template.render(values))
Finally, within my html page I have:
{% for r in feeds.entries %}
<a href={{r.link}} target=_blank>{{r.title}}</a>: {{r.description}}
<br/>
{% endfor %}
When I use feedparser on the feeds individually I can pass the information but when I try merging the feeds nothing shows. I have imported feedparser and Future.
Your sorted() call is missing a closing paren.
I'm trying to merge RSS feeds using python and then play them back out to a website. Having researched the recommended methods I've opted for the following code which is basically a straight copy of what is recommended:
hit_list = ['http://www.bbc.co.uk/sport/football/teams/cardiff-city/rss.xml','http://www1.skysports.com/feeds/11704/news.xml','http://www.cardiffcity-mad.co.uk/rssfeeds/rssfull.asp']
# pull down all feeds
future_calls = [Future(feedparser.parse,rss_url) for rss_url in hit_list]
# block until they are all in
feeds = [future_obj() for future_obj in future_calls]
#Now that you have your feeds, extract all the entries
entries = []
for feed in feeds:
entries.extend(feed["items"])
values['feeds'] = sorted(entries, key=lambda entry: entry["updated_parsed"])
Later, I call the web using:
template = jinja_environment.get_template('TeamView.html')
self.response.out.write(template.render(values))
Finally, within my html page I have:
{% for r in feeds.entries %}
<a href={{r.link}} target=_blank>{{r.title}}</a>: {{r.description}}
<br/>
{% endfor %}
When I use feedparser on the feeds individually I can pass the information but when I try merging the feeds nothing shows. I have imported feedparser and Future.
I've found the answer by breaking down the output. The for loop is taking out the entries tag and holding them at higher level so my html needs to be:
{% for r in feeds %}
<a href={{r.link}} target=_blank>{{r.title}}</a>: {{r.description}}
<br/>
{% endfor %}
Works perfectly now