How to use YQL to merge 2 RSS feeds sorted by pubD

2020-07-18 07:36发布

Seeing that YQL is being promoted as a good way to do things, I was curious as to how to use YQL to fetch and merge 2 different feeds into one (sorted by pubDate).

It's pretty trivial to fetch 2 feeds but it turns out that the feeds are just concatenated together and not merged.

Here's the sample code.

select channel.title,channel.link,channel.item.title,channel.item.link
    from xml where url in(
      'http://code.flickr.com/blog/feed/rss/',
      'http://feeds.delicious.com/v2/rss/codepo8?count=15',
      'http://www.stevesouders.com/blog/feed/rss',
      'http://www.yqlblog.net/blog/feed/',
      'http://www.quirksmode.org/blog/index.xml'
    )

3条回答
该账号已被封号
2楼-- · 2020-07-18 07:48

As to the RSS question - YQL always returns XML - if you want to turn it into an RSS feed you can also use Yahoo Pipes and the YQL module to get it as RSS.

查看更多
别忘想泡老子
3楼-- · 2020-07-18 08:00

This should do the trick

select channel.item.title,channel.item.link, channel.item.pubDate
    from xml where url in(
      'http://code.flickr.com/blog/feed/rss/',
      'http://feeds.delicious.com/v2/rss/codepo8?count=15',
      'http://www.stevesouders.com/blog/feed/rss',
      'http://www.yqlblog.net/blog/feed/',
      'http://www.quirksmode.org/blog/index.xml'
    )
  | unique(field="channel.item.link")
  | sort(field="channel.item.pubDate", descending="true")

use the post-query functions unique to filter out duplicates and sort to re-order your result. Here the link to the documentation of those functions http://developer.yahoo.com/yql/guide/sorting.html

查看更多
祖国的老花朵
4楼-- · 2020-07-18 08:03

Thanks for this info. It works when accessing the rss object, too:

select title,link,pubDate from rss where url in (
    'http://feeds.delicious.com/v2/rss/hasematzel?count=3',
    'http://oliverschwarz.tumblr.com/rss',
    'http://twitter.com/statuses/user_timeline/818226.rss',
    'http://hasematzel.de/blog/feed/',
    'http://piepmatzel.de/feed/'
) | sort(field="pubDate", descending="true")

This is a very simple way to create a newsroom or a lifestream. Don't forget to force-cache the YQL return :)

查看更多
登录 后发表回答