added option to cursor() to yeild "page" - ie: iterators over each page returned by twitter #282
No reviewers
Labels
No labels
Bug
Enhancement
Feature Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: code/twython#282
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "cursor-pages"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When using cursors of the twitter api, results come back in "pages", with each page returned from a separate api call. If you want to track how many api calls you're making (not a bad idea if twitter's rate limit status is being unreliable, as in my case), it's handy to know how many calls a cursor is making as you iterate through it.
This pull request adds an option to
returnPages = Falsethecursor()function. If set toTrue,cursor()yields an iterator for each page returned by twitter.Can't you just count how many times you loop over the generator?
with the current implementation of
cursor(), you'll count the number of objects returned by twitter, not the number of api calls it took to get them - they come from twitter lots-at-a-time (eg: 5000 user id's when callingfriends/ids.jsonHi! Sorry I haven't gotten around to looking at this (it's been too long :X) The easiest way to get this pull request up-to-date would probably be pull from
masterand then re-add your changes tocursorAlso, instead of
returnPages; can you usereturn_pages(Per http://www.python.org/dev/peps/pep-0008/#function-names)And if you could remove the space: right now you have
returnPages = FalseandreturnPages = returnPageswherereturn_pages=Falseandreturn_pages=return_pageswould go with PEP8 standards.Sorry if this causes an inconvenience :( If you need any help, let me know! Hope to see this Pull Request updated so we can merge this functionality in!
Coverage decreased (-0.19%) when pulling
e1ee67192eon drevicko:cursor-pages intoda3a0bb9fcon ryanmcgrath:master.While we're here, did you play with the other pull request I put in #284?
I'll merge that with master in case you want to include it.
Yeah, I know how it is. I've got lots of 'real' work on at the moment, so procrasta-github is taking a bit of a back seat! ;)
Oh, and no inconvenience - it's only a few minutes to merge (:
@drevicko Seems as though merging #284 broke this merge :(
@drevicko Just wanted to ping you again. Sorry about the inconvenience! 🍰
that should do it.. I'm not really in a position to test it at the moment, but if travis is happy?
Something I noticed: in my production version of twython, I've changed some of the exception handling: I always raise an exception if I can't parse the response as json, even if twitter returns a 200, 201 or 202 status. I think it was causing me problems (maybe the api was broken or something? It's a while ago, and I can't remember clearly). It's on line 197 of api.py . I've not pushed it to github yet - might do that now if you want to have a look.
I would maybe do another pull request for that fix. I'll merge this in and then test for myself over the next couple days and do a release next week! Thanks!
glad to help out (:
and thanks for putting twython together :)