Skip to content

Commit

Permalink
Fixed a bug and added example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew A. Russell committed Jan 28, 2011
1 parent 85aef39 commit 2d3fd0b
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions 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,
Expand All @@ -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 = {}

Expand All @@ -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.