Open GoogleCodeExporter opened 8 years ago
OK, this has annoyed me so much I rewrote the thing. Working version below.
Someone should check it, I've been a C programmer for 20 years, but python less
than a week.
=================
def GetFollowers(self, cursor=-1, rate_limit=350):
'''Fetch the sequence of twitter.User instances, one for each follower
The twitter.Api instance must be authenticated.
Args:
cursor:
Specifies the Twitter API Cursor location to start at. [Optional]
Note: there are pagination limits.
rate_limit:
Specifies the Twitter rate limit. Defaults to 350. Individuals are limited
to 150
Returns:
A sequence of twitter.User instances, one for each follower
'''
if not self._oauth_consumer:
raise TwitterError("twitter.Api instance must be authenticated")
url = '%s/statuses/followers.json' % self.base_url
result = []
rate_check = 1
while True:
parameters = { 'cursor': cursor }
json = self._FetchUrl(url, parameters=parameters)
data = self._ParseAndCheckTwitter(json)
result += [User.NewFromJsonDict(x) for x in data['users']]
if 'next_cursor' in data:
cursor = data['next_cursor']
if data['next_cursor'] == 0 or data['next_cursor'] == data['previous_cursor']:
break
else:
break
if rate_check == rate_limit:
break
else:
rate_check += 1
return result
=============
Original comment by rick.dea...@gmail.com
on 21 Sep 2011 at 2:42
Looks good to me -- Python coder for 10 years, twitter hacker for ten minutes
Original comment by jamiesonbecker@gmail.com
on 21 Sep 2011 at 9:55
Original issue reported on code.google.com by
jacob.so...@me.com
on 8 Jun 2011 at 5:46