eventbrite-sdk-python
eventbrite-sdk-python copied to clipboard
Pagination improvements
The underlying REST API supports paging, but it is masked in a few places by overly-strict function signatures.
When a function gets called from the AccessMethodsMixin
collection, the page=1
keyword argument gets passed along to the REST request. However some of the functions defined in the Eventbrite
class (such as get_event_attendees
) mask the auto-generated functions and don't have the page
keyword argument, so there's no way to get to the second page.
It would also be nice to have a helper utility to automatically retrieve the pages.
Was asked about this in IRC over the weekend. Need to either document pagination or make it easier to do.
Yes, this functionality is critical! Without it, the scripts I have are worthless, really. It took me forever to track down how to specify the page number, so I'll share here the python function that can call a specific page of attendees.
#define as variables YOUREVENTID and YOURAUTHTOKEN
def get_page(pn): #pn is page number
pn=str(pn)
response = requests.get(
"https://www.eventbriteapi.com/v3/events/"+YOUREVENTID+"/attendees/?page="+pn+"&token="+YOURAUTHTOKEN,
verify = True,
)
return response.json()
This should be high priority to fix. I might be able to send a PR later, but what I did for now was to subclass Eventbrite and implement a get_all_event_attendees function that cycles through the pagination. This has poor guarantees for completeness, but it's better than completely missing out on any page > 1
class MyEventbrite(Eventbrite):
def get_event_attendees(self, event_id, status=None,
changed_since=None, page=1):
"""
Returns a paginated response with a key of attendees, containing a
list of attendee.
GET /events/:id/attendees/
"""
data = {}
if status: # TODO - check the types of valid status
data['status'] = status
if changed_since:
data['changed_since'] = changed_since
data['page'] = page
return self.get("/events/{0}/attendees/".format(event_id), data=data)
def get_all_event_attendees(self, event_id, status=None,
changed_since=None):
"""
Returns a full list of attendees.
TODO: figure out how to use the 'continuation' field properly
"""
page = 1
attendees = []
while True:
r = self.get_event_attendees(event_id, status,
changed_since, page=page)
attendees.extend(r['attendees'])
if r['pagination']['page_count'] <= page:
break
page += 1
return attendees
Is there still no pagination support?
This is still unresolved. I don't see a way to use the API to get a second page or use a continuation value, especially for get_event_attendees, which won't take arbitrary keyword arguments and doesn't have arguments defined for pages/continuation.
Ran into the same problem. I use get
instead of get_event_attendees
:
e.g.
data = {'page': page}
response = eventbrite.get(attendees_path, data)
This has been resolved and is well documented on the Eventbrite website
@larkinds it's easy with the rest api, but the python API doesn't expose it.