Py-StackExchange icon indicating copy to clipboard operation
Py-StackExchange copied to clipboard

listing badges

Open foobarbecue opened this issue 9 years ago • 1 comments

.badges docstring says it returns users, but actually it just seems to return the badge object. Is this the intended behavior?

In [60]: so = stackexchange.Site('stackoverflow')

In [61]: so.badges?
Type:       instancemethod
String Form:<bound method Site.badges of <stackexchange.Site object at 0x7fc1150b3210>>
File:       /home/aaron/sandbox/Py-StackExchange/demo/build/bdist.linux-x86_64/egg/stackexchange/__init__.py
Definition: so.badges(self, ids=None, **kw)
Docstring:  Returns the users with the badges with IDs.

In [62]: so.badges(22)
Out[62]: (<Badge 'Great Question' @ 7fc1150b3d90>)

foobarbecue avatar Feb 09 '16 17:02 foobarbecue

Sorry for the late reply, thanks a lot for pointing this out to me. That is indeed a documentation issue, which I've fixed in the latest commit.

While digging into it, however, there were a few other issues with the badge methods which should now be fixed in the latest commit. If you want to get the recipients of a particular badge, you can use the recipients field of the Badge object, e.g. so.badge(22).recipients. Bear in mind this is an 'infinite' generator, so don't try and turn it into a list all at once. For something closer to the documented API endpoint, the Site#badge_recipients method returns a set of Badges as described here.

lucjon avatar Feb 21 '16 20:02 lucjon