本文整理汇总了Python中twitter.Twitter.user_lookup方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.user_lookup方法的具体用法?Python Twitter.user_lookup怎么用?Python Twitter.user_lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter.Twitter
的用法示例。
在下文中一共展示了Twitter.user_lookup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_lookup
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import user_lookup [as 别名]
def test_user_lookup(self):
tw = Twitter(**self.SETTINGS)
print("Twitter object: ", tw)
tw.get_access_token()
user = tw.user_lookup(screen_name='neokluber')
print("Twitter username: ", user)
assert user[0]['id_str']
示例2: test_get_friends
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import user_lookup [as 别名]
def test_get_friends(self):
tw = Twitter(**self.SETTINGS)
print("Twitter object: ", tw)
tw.get_access_token()
user = tw.user_lookup(screen_name='neokluber')
uid = user[0]['id_str']
friend_list = tw.get_friends(uid)
print("Friends list: ", friend_list)
assert isinstance(friend_list, list)
assert friend_list
示例3: main
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import user_lookup [as 别名]
def main(filename, screen_name):
"""
filename : json settings file see the sample file in repository
screen_name : screen name of a twitter user
"""
with open(filename, 'r') as f:
settings = json.load(f)
twitter = Twitter(**settings)
twitter.get_access_token()
# Graph structure { node_a: [connected_node_1, connected_node_2,..]}
graph = {}
self_limit(twitter, 'users/lookup', 3)
try:
uid = call_api(twitter.user_lookup(screen_name=screen_name),
3)[0]['id_str']
except Exception:
logging.debug("Error getting twitter userid: " + screen_name)
raise
self_limit(twitter, 'friends/ids', 3)
try:
graph[uid] = call_api(twitter.get_friends(uid), 3)
except Exception:
logging.debug("Error getting friends list")
raise
# Get friends' friends and add to nodes; graph[friend] = [their friends]
for friend in graph[uid]:
self_limit(twitter, 'friends/ids', 3)
try:
graph[friend] = call_api(twitter.get_friends(friend), 3)
except Exception:
logging.debug("Error getting friends' friends!")
raise
# No point in hitting twitter too fast
sleep(10)
# Find indegree of connected nodes and build a frequency table. The freq
# table can be used to idenfity nodes to include in the graph. ie include
# only those users with at least 2 followers within the network.
freq = {}
freq[uid] = 0 # because main user may not appear in the below list
for node in [x for y in graph.values() if y is not None for x in y]:
if node in freq:
freq[node] += 1
else:
freq[node] = 1
# Add main user and friends to a list. Indices of elements in this list
# will be used later to build graph node source->target table for d3.js
node_list = graph.keys()
# Add friends of friends to node list if they're friends with more than 1
for node in [x for x in freq if freq[x] > 5]:
if node not in node_list:
node_list.append(node)
logging.info(('Found %s vertices for the graph') % (len(node_list)))
# Get user's name and screen name; store it in a dict for lookup later
# bunch 100 ids into a comma separated query string
n = 0
query_str = ''
user_details = {}
for user in node_list:
n += 1
query_str += user + ","
if (n % 100 == 0) or n == len(node_list):
try:
r = call_api(twitter.user_lookup(id=query_str), 3)
except Exception:
logging.debug("Error getting details for: " + user)
raise
for rec in r:
# user_details[user_id] = [name, screen_name].
user_details[rec['id_str']] = [rec.get('name'),
rec.get('screen_name')]
query_str = ''
# Build json for d3.js
# {
# "nodes" : [
# {"name": Name, "scr_name": Screen Name, "degree": Degree},
# {"name": Name, "scr_name": Screen Name, "degree": Degree},
# ],
# "links" : [
# {"source": index of source, "target": index of target},
# {"source": index of source, "target": indext of target}
# ]
# }
d3_json = {
"nodes": [],
#.........这里部分代码省略.........