jonnybot
jonnybot

Reputation: 2453

Get first n entries from rss or atom feed using YQL and feednormalizer

I'm using YQL to retrieve RSS and ATOM feeds as JSON, and normalize them to ATOM style using the feednormalizer table.

select * from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb'

I need to get only the first X entries. I know that, in theory, an xpath expression should be able to do that. However, when I try one that I assume ought to work...

select * from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb' AND xpath='//entry[count(preceding::entry) < 5]'

...the results object comes back null. I've also tried using item instead of entry in the xpath query, since that's what an RSS feed will have in the actual XML. That also returns a null results object.

Other Stuff I've Tried

Limits

I've also tried using both local and remote limits, which returns the same number of entries as if I hadn't specified a limit.

select * from feednormalizer(0,5) where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb'

select * from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb' limit 6

Selecting Columns with CrossProduct

Notably, I still need all the metadata that comes with the typical select * query. That is, I need the feed's title, link, etc., and I'd prefer they stayed at the root element. So, I know that I can do

select title, link, entry from feednormalizer(0,6) where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb'

or

select title, link, entry from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb' limit 6

But that puts the title and feed link directly onto each entry in the list, even with crossProduct=optimized in the URL string. Call me picky, but I'd rather not do that.

Upvotes: 2

Views: 681

Answers (1)

kenfire
kenfire

Reputation: 1355

Might be really late but for others like me that had the same question, I finished by doing 2 requests. The first one for meta data:

select * from feednormalizer 
where output='atom_1.0' 
AND url='http://feeds.delicious.com/v2/rss/msuweb'

and the second one to limit the data:

select title, link, entry 
from feednormalizer(0,6) 
where output='atom_1.0' 
AND url='http://feeds.delicious.com/v2/rss/msuweb'

! Not optimized but works !

Upvotes: 0

Related Questions