Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit 0341e60

Browse files
authored
Merge pull request #448 from bear/fix/issue446
Fix issue with set indexing in UsersLookup
2 parents a3118bd + 39090a7 commit 0341e60

1 file changed

Lines changed: 22 additions & 33 deletions

File tree

twitter/api.py

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,47 +2825,38 @@ def UsersLookup(self,
28252825
are queried is the union of all specified parameters.
28262826
28272827
Args:
2828-
user_id:
2829-
A list of user_ids to retrieve extended information. [Optional]
2830-
screen_name:
2831-
A list of screen_names to retrieve extended information. [Optional]
2832-
users:
2828+
user_id (int, list, optional):
2829+
A list of user_ids to retrieve extended information.
2830+
screen_name (str, optional):
2831+
A list of screen_names to retrieve extended information.
2832+
users (list, optional):
28332833
A list of twitter.User objects to retrieve extended information.
2834-
[Optional]
2835-
include_entities:
2834+
include_entities (bool, optional):
28362835
The entities node that may appear within embedded statuses will be
2837-
disincluded when set to False. [Optional]
2836+
excluded when set to False.
28382837
28392838
Returns:
28402839
A list of twitter.User objects for the requested users
28412840
"""
2842-
if not user_id and not screen_name and not users:
2843-
raise TwitterError({'message': "Specify at least one of user_id, screen_name, or users."})
2841+
if not any([user_id, screen_name, users]):
2842+
raise TwitterError("Specify at least one of user_id, screen_name, or users.")
28442843

28452844
url = '%s/users/lookup.json' % self.base_url
2846-
parameters = {}
2845+
parameters = {
2846+
'include_entities': include_entities
2847+
}
28472848
uids = list()
28482849
if user_id:
28492850
uids.extend(user_id)
28502851
if users:
28512852
uids.extend([u.id for u in users])
28522853
if len(uids):
2853-
parameters['user_id'] = ','.join(["%s" % u for u in uids])
2854+
parameters['user_id'] = ','.join([str(u) for u in uids])
28542855
if screen_name:
28552856
parameters['screen_name'] = ','.join(screen_name)
2856-
if not include_entities:
2857-
parameters['include_entities'] = 'false'
28582857

28592858
resp = self._RequestUrl(url, 'GET', data=parameters)
2860-
try:
2861-
data = self._ParseAndCheckTwitter(resp.content.decode('utf-8'))
2862-
except TwitterError as e:
2863-
_, e, _ = sys.exc_info()
2864-
t = e.args[0]
2865-
if len(t) == 1 and ('code' in t[0]) and (t[0]['code'] == 34):
2866-
data = []
2867-
else:
2868-
raise
2859+
data = self._ParseAndCheckTwitter(resp.content.decode('utf-8'))
28692860
return [User.NewFromJsonDict(u) for u in data]
28702861

28712862
def GetUser(self,
@@ -2875,29 +2866,27 @@ def GetUser(self,
28752866
"""Returns a single user.
28762867
28772868
Args:
2878-
user_id:
2879-
The id of the user to retrieve. [Optional]
2880-
screen_name:
2869+
user_id (int, optional):
2870+
The id of the user to retrieve.
2871+
screen_name (str, optional):
28812872
The screen name of the user for whom to return results for.
28822873
Either a user_id or screen_name is required for this method.
2883-
[Optional]
2884-
include_entities:
2874+
include_entities (bool, optional):
28852875
The entities node will be omitted when set to False.
2886-
[Optional]
28872876
28882877
Returns:
28892878
A twitter.User instance representing that user
28902879
"""
28912880
url = '%s/users/show.json' % (self.base_url)
2892-
parameters = {}
2881+
parameters = {
2882+
'include_entities': include_entities
2883+
}
28932884
if user_id:
28942885
parameters['user_id'] = user_id
28952886
elif screen_name:
28962887
parameters['screen_name'] = screen_name
28972888
else:
2898-
raise TwitterError({'message': "Specify at least one of user_id or screen_name."})
2899-
if not include_entities:
2900-
parameters['include_entities'] = 'false'
2889+
raise TwitterError("Specify at least one of user_id or screen_name.")
29012890

29022891
resp = self._RequestUrl(url, 'GET', data=parameters)
29032892
data = self._ParseAndCheckTwitter(resp.content.decode('utf-8'))

0 commit comments

Comments
 (0)