Guest User

Untitled

a guest
Mar 27th, 2011
3,488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import tweepy
  2.  
  3. auth = tweepy.OAuthHandler('consumer key', 'consumer secret')
  4. auth.set_access_token('access key', 'access secret')
  5. api = tweepy.API(auth)
  6.  
  7. user= "karpathy" #me :)
  8.  
  9. #limit per hour is 350 calls
  10. limit= api.rate_limit_status()['remaining_hits']
  11. print 'you have', limit, 'API calls remaining until next hour'
  12.  
  13. #retrieve only the latest 100 of people who I follow
  14. #COST: 1 API call = 100 users
  15. for friend in tweepy.Cursor(api.friends, id=user).items(100):
  16.     #friend is an object with some fields
  17.     print friend.screen_name
  18.    
  19. #to retrieve all followers etc, just leave the argument to items() blank.
  20.  
  21. #retrieve 100 of my latest followers
  22. #COST: 1 API call = 100 users
  23. for follower in tweepy.Cursor(api.followers).items(100):
  24.     print follower.screen_name
  25.    
  26. #all status updates from user.
  27. #COST: 1 API call= 20 users
  28. for status in tweepy.Cursor(api.user_timeline, id=user).items(20):
  29.     #status is an object with many fields and info
  30.     print status.text
  31.    
  32. limit= api.rate_limit_status()['remaining_hits']
  33. print 'now you only have', limit, 'API calls.'
Advertisement
Add Comment
Please, Sign In to add comment