Вопрос

Is there an elegant way of paging through boto.resultset.ResultSet, e.g.:

amt = boto.mturk.connection.MTurkConnection()
qualid = "XXX"
quals = amt.get_qualifications_for_qualification_type( qualid, page_size=100, page_number=1 )
# quals becomes boto.resultset.ResultSet with just 100 items

The last query can return several pages of results. Given that there are many queries in boto returning several pages of results, isn't there any elegant way to iterate over all the results?

Это было полезно?

Решение

All right, I'm using my own solution:

def get_entire_resultset( query, *args, **kargs ):
   ps = 100; pn = 1
   objs = query( *args, page_size=ps, page_number=pn, **kargs )
   total_downloaded = ps
   pn += 1
   total = int(objs.TotalNumResults)
   while total_downloaded<total:
      objs.extend( query( *args, page_size=ps, page_number=pn, **kargs ) )
      total_downloaded += ps
      pn += 1
   return objs

That is used as follows:

quals = get_entire_resultset( amt.get_qualifications_for_qualification_type, qualid )
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top