0

Selecting Medium format from Flickr

The query below works a treat:

SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434"

But, if my app submits multiple photos, I need to get only those that offer a 'Medium' size option. I thought something like the below would work:

SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" AND query.results.rsp.sizes.size.label="Medium"

I was, sadly, wrong.

What have I missed?

by
9 Replies
  • QUOTE (lachlanhardy @ Feb 11 2009, 03:31 AM) <{POST_SNAPBACK}>
    SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" AND query.results.rsp.sizes.size.label="Medium"


    To my mind, this should also work:
    SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" and xpath="//size[@label='Medium']"
    0
  • I haven't worked with the Flickr API, so I'd suggest you visit their forum. Flickr's forum is here: http://code.flickr.com/forum/

    Robyn Tippins
    Community Manager, YDN
    0
  • QUOTE (lachlanhardy @ Feb 11 2009, 03:31 AM) <{POST_SNAPBACK}>
    The query below works a treat:

    SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434"

    But, if my app submits multiple photos, I need to get only those that offer a 'Medium' size option. I thought something like the below would work:

    SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" AND query.results.rsp.sizes.size.label="Medium"

    I was, sadly, wrong.

    What have I missed?

    It looks like you can use
    SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" and itemPath="rsp" and sizes.size.label='Medium'
    0
  • QUOTE (hapdaniel @ Feb 11 2009, 11:48 AM) <{POST_SNAPBACK}>
    It looks like you can use
    SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" and itemPath="rsp" and sizes.size.label='Medium'


    So I think what he wants is this:

    SELECT sizes.size FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" and itemPath="rsp" and sizes.size.label='Medium'

    The issue is that * returns any matching element at the top level. The rsp element is the only one at the top level and it satisfies the filter as it contains a sizes.size.label element that is equal to Medium. If you *only* want the size element that matches then you need to project out that element and YQL magic will do the right thing.
    0
  • QUOTE (hapdaniel @ Feb 11 2009, 11:48 AM) <{POST_SNAPBACK}>
    It looks like you can use
    SELECT * FROM xml WHERE url="http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=41c85efb4676ea8060b400cdd8de3df4&photo_id=3271002434" and itemPath="rsp" and sizes.size.label='Medium'


    We do have a flickr.photos.sizes table too that also gets the information:

    CODE
    select source from flickr.photos.sizes where photo_id=3271002434 and label="Medium"


    Jonathan
    0
  • Thanks for all your help, folks!

    What I'm actually after in the long run, is a query that will retrieve a specified number of photos based on tags they have AND which are available in Large format. The example I used above was for the sub-select.

    Thus far, I'm still unable to get it to work.
    0
  • I spent a bit of time on it this evening and it works an absolute treat. I ended up with:

    CODE
    SELECT *
    FROM flickr.photos.sizes
    WHERE label="Large"
    AND photo_id IN (
    SELECT id
    FROM flickr.photos.search
    WHERE tags = "party"
    )


    I used it in a little Sinatra app that you can see at http://streamslide.com/

    No where near finished yet, of course, but at least the query will exclude images that are aren't available at large enough sizes now. Thanks very much for your help everyone!
    0
  • QUOTE (lachlanhardy @ Feb 18 2009, 05:24 AM) <{POST_SNAPBACK}>
    I spent a bit of time on it this evening and it works an absolute treat. I ended up with:

    CODE
    SELECT *
    FROM flickr.photos.sizes
    WHERE label="Large"
    AND photo_id IN (
    SELECT id
    FROM flickr.photos.search
    WHERE tags = "party"
    )


    I used it in a little Sinatra app that you can see at http://streamslide.com/

    No where near finished yet, of course, but at least the query will exclude images that are aren't available at large enough sizes now. Thanks very much for your help everyone!


    Nice example. This is filtering locally in YQL to remove entries from the data that comes back from flickr.
    0
  • QUOTE (Jonathan @ Feb 18 2009, 01:43 PM) <{POST_SNAPBACK}>
    Nice example. This is filtering locally in YQL to remove entries from the data that comes back from flickr.


    Exactly! It's way quicker if I get Yahoo! to do it than if I try and make my poor slice do it. It also means I don't have to write the code locally to sort it out.

    Made a great example for my preso on YQL at the local Ruby meetup last week too ;) (I'll post slides etc this weekend, probably)
    0

Recent Posts

in YQL