alexis-mignon / python-flickr-api

A python implementation of the Flickr API
BSD 3-Clause "New" or "Revised" License
367 stars 108 forks source link

Accessing data returned from extras #108

Closed Scraft closed 5 years ago

Scraft commented 5 years ago

I have looked through the API to see if I am missing something, but right now I do not see how it is possible to get data requested via extras. A specific example:

photoSet.getPhotos(extras='date_taken')

https://www.flickr.com/services/api/flickr.photosets.getPhotos.html

When this is passed, the Flickr HTTP end point provides a 'datetaken' field for each photo, it is unclear to me if I can access this with python-flickr-api. To hack a solution I tried adding dict_converter(["datetaken"], str), to the below:

class Photo(FlickrObject):
    __converters__ = [
        dict_converter(["isfamily", "ispublic", "isfriend", "cancomment",
                        "canaddmeta", "permcomment", "permmeta", "isfavorite"],
                        bool),
        dict_converter(["posted", "lastupdate"], int),
        dict_converter(["views", "comments"], int),
        dict_converter(["datetaken"], str),
    ]

This was successful, and I was then able to access this via: photo.datetaken. The reason I would like to access this field, is I realised by doing this I can massively cut down on my HTTP end point calls (rather than one for every single photo, I can get 500 photos per album at a time with the date.

So immediately I would like to find out if there is a solution for my use case which doesn't require me to hack python-flickr-api secondly I would like to know if this solution extends to using any other of these extra type parameters. If there isn't a generic answer, perhaps you can guide me how to use the API in the advanced mode mentioned in the documents to achieve my goal?

mtrovo commented 5 years ago

All fields on the response are added to the object itself. You don't need to mess with the Photo class source code to do it.

For this specific example the content of the extra date_taken are provided as the keys: datetaken, datetakengranularity, datetakenunknown.

And to access the field itself you just need to do a photo.datetaken for example.

Scraft commented 5 years ago

Perfect; after messing around with the source, I thought I had introduced the datetaken field, but you are right, it all 'just works'.