Skip to content
Browse files

Fixed a bug and added example usage

  • Loading branch information...
1 parent 85aef39 commit 2d3fd0b684b0ba099067978793a4f4d588332c8f @ptwobrussell committed Jan 28, 2011
Showing with 22 additions and 5 deletions.
  1. +22 −5 recipe__get_user_info.py
View
27 recipe__get_user_info.py
@@ -1,22 +1,21 @@
# -*- coding: utf-8 -*-
+from recipe__oauth_login import oauth_login
from recipe__make_twitter_request import make_twitter_request
-# XXX: TEST ME
-
# Assume ids have been fetched from a scenario such as the
# one presented in recipe__get_friends_followers.py and that
# t is an authenticated instance of twitter.Twitter
-def getInfoById(t, ids):
+def get_info_by_id(t, ids):
id_to_info = {}
while len(ids) > 0:
# Process 100 ids at a time...
- ids_str, ids = ','.join([str(_id) for _id in ids[:100]])
+ ids_str = ','.join([str(_id) for _id in ids[:100]])
ids = ids[100:]
response = make_twitter_request(t,
@@ -38,7 +37,7 @@ def getInfoById(t, ids):
# using code that's virtually identical. These two functions
# could easily be combined.
-def getInfoByScreenName(t, screen_names):
+def get_info_by_screen_name(t, screen_names):
sn_to_info = {}
@@ -63,3 +62,21 @@ def getInfoByScreenName(t, screen_names):
sn_to_info[user_info['screen_name']] = user_info
return sn_to_info
+
+if __name__ == '__main__':
+
+ # Be sure to pass in any necessary keyword parameters
+ # if you don't have a token already stored on file
+
+ t = oauth_login()
+
+ # Basic usage...
+
+ info = {}
+ info.update(get_info_by_screen_name(t, ['ptwobrussell', 'socialwebmining']))
+ info.update(get_info_by_id(t, ['2384071']))
+
+ # Do something useful with the profile information like store it to disk
+
+ import json
+ print json.dumps(info, indent=1)

0 comments on commit 2d3fd0b

Please sign in to comment.
Something went wrong with that request. Please try again.