Added a new bulkUserLookup() method. Takes two optional arrays of user_ids or screen_names and returns data from Twitter concerning all the users in question. (e.g, lol.bulkUserLookup(user_ids=[1,2,3], screen_names=["danmcgrath", "enotionz", "shiftb"])"

This commit is contained in:
Ryan McGrath 2010-03-17 03:19:41 -04:00
parent 8bea592d97
commit fe59e56361
2 changed files with 58 additions and 6 deletions

View file

@ -16,7 +16,7 @@ from urllib.parse import urlparse
from urllib.error import HTTPError
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
__version__ = "1.0"
__version__ = "1.1"
"""Twython - Easy Twitter utilities in Python"""
@ -53,7 +53,7 @@ class AuthError(TwythonError):
class setup:
def __init__(self, username = None, password = None, headers = None, proxy = None, version = 1):
"""setup(authtype = "OAuth", username = None, password = None, proxy = None, headers = None)
"""setup(username = None, password = None, proxy = None, headers = None)
Instantiates an instance of Twython. Takes optional parameters for authentication and such (see below).
@ -115,7 +115,7 @@ class setup:
Parameters:
url_to_shorten - URL to shorten.
shortener - In case you want to use url shorterning service other that is.gd.
shortener - In case you want to use a url shortening service other than is.gd.
"""
try:
return urllib.request.urlopen(shortener + "?" + urllib.urlencode({query: self.unicode2utf8(url_to_shorten)})).read()
@ -463,6 +463,32 @@ class setup:
except HTTPError as e:
raise TwythonError("showUser() failed with a %s error code." % repr(e.code), e.code)
def bulkUserLookup(self, ids = None, screen_names = None, version = None):
""" bulkUserLookup(self, ids = None, screen_names = None, version = None)
A method to do bulk user lookups against the Twitter API. Arguments (ids (numbers) / screen_names (strings)) should be flat Arrays that
contain their respective data sets.
Statuses for the users in question will be returned inline if they exist. Requires authentication!
"""
version = version or self.apiVersion
if self.authenticated is True:
apiURL = "http://api.twitter.com/%d/users/lookup.json?lol=1" % version
if ids is not None:
apiURL += "&user_id="
for id in ids:
apiURL += repr(id) + ","
if screen_names is not None:
apiURL += "&screen_name="
for name in screen_names:
apiURL += name + ","
try:
return simplejson.load(self.opener.open(apiURL))
except HTTPError as e:
raise TwythonError("bulkUserLookup() failed with a %s error code." % repr(e.code), e.code)
else:
raise AuthError("bulkUserLookup() requires you to be authenticated.")
def getFriendsStatus(self, id = None, user_id = None, screen_name = None, page = None, cursor="-1", version = None):
"""getFriendsStatus(id = None, user_id = None, screen_name = None, page = None, cursor="-1")