Merging RSS Feeds in Python

14 views
Skip to first unread message

user2740177 via StackOverflow

unread,
Sep 15, 2013, 2:35:19 AM9/15/13
to google-appengin...@googlegroups.com

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.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/18809575/merging-rss-feeds-in-python

akn320 via StackOverflow

unread,
Sep 15, 2013, 11:16:38 PM9/15/13
to google-appengin...@googlegroups.com

Your sorted() call is missing a closing paren.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/18809575/merging-rss-feeds-in-python/18819929#18819929

user2740177 via StackOverflow

unread,
Sep 16, 2013, 2:03:16 PM9/16/13
to google-appengin...@googlegroups.com

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:

']
    # 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.



user2740177 via StackOverflow

unread,
Sep 17, 2013, 1:23:42 AM9/17/13
to google-appengin...@googlegroups.com

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



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/18809575/merging-rss-feeds-in-python/18841816#18841816
Reply all
Reply to author
Forward
0 new messages