本文整理汇总了Python中twython.Twython.get_followers_list方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.get_followers_list方法的具体用法?Python Twython.get_followers_list怎么用?Python Twython.get_followers_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.get_followers_list方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: twitter
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
def twitter(username):
out = {'success':False};
APP_KEY = "YOUR KEY HERE"
APP_SECRET= "YOUR SECRET HERE"
OAUTH_TOKEN = "YOUR TOKEN HERE"
OAUTH_TOKEN_SECRET = "YOUR TOKEN SECRET HERE"
# Requires Authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
user_timeline = twitter.get_user_timeline(screen_name=username)
followers = twitter.get_followers_list(screen_name = username)
out['victims'] = [];
out['success'] = True
for follower_id in followers["users"]:
try:
out['victims'].append({'name':follower_id["name"], 'lastWords':follower_id["status"]["text"]})
except KeyError:
print "bad twitter user. bad."
except TwythonError as e:
print e
#print user_timeline
txt = simplejson.dumps(out, indent=4 * ' ')
return txt
示例2: findFollowersOf
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
def findFollowersOf(user):
twitter = Twython(APP_KEY, APP_SECRET);
followerList = [];
# Cursoring over follower pages
mycursor = -1;
for i in range(0,5):
print 'Cursor page '+str(i);
f = twitter.get_followers_list(
screen_name=user,cursor=mycursor,count=20,skip_status='true',include_user_entities='true');
for follower in f['users']:
followerList.append((follower['screen_name'],follower['followers_count']));
mycursor = f['next_cursor'];
print 'Got list, sorting'
return sorted(followerList,key=lambda followers:followers[1],reverse=True);
示例3: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
#.........这里部分代码省略.........
'''Test returning incoming friendship ids succeeds'''
self.api.get_incoming_friendship_ids()
def test_get_outgoing_friendship_ids(self):
'''Test returning outgoing friendship ids succeeds'''
self.api.get_outgoing_friendship_ids()
def test_create_friendship(self):
'''Test creating a friendship succeeds'''
self.api.create_friendship(screen_name='justinbieber')
def test_destroy_friendship(self):
'''Test destroying a friendship succeeds'''
self.api.destroy_friendship(screen_name='justinbieber')
def test_update_friendship(self):
'''Test updating friendships succeeds'''
self.api.update_friendship(screen_name=protected_twitter_1,
retweets='true')
self.api.update_friendship(screen_name=protected_twitter_1,
retweets='false')
def test_show_friendships(self):
'''Test showing specific friendship succeeds'''
self.api.show_friendship(target_screen_name=protected_twitter_1)
def test_get_friends_list(self):
'''Test getting list of users authenticated user then random user is
following succeeds'''
self.api.get_friends_list()
self.api.get_friends_list(screen_name='twitter')
def test_get_followers_list(self):
'''Test getting list of users authenticated user then random user are
followed by succeeds'''
self.api.get_followers_list()
self.api.get_followers_list(screen_name='twitter')
# Users
def test_get_account_settings(self):
'''Test getting the authenticated user account settings succeeds'''
self.api.get_account_settings()
def test_verify_credentials(self):
'''Test representation of the authenticated user call succeeds'''
self.api.verify_credentials()
def test_update_account_settings(self):
'''Test updating a user account settings succeeds'''
self.api.update_account_settings(lang='en')
def test_update_delivery_service(self):
'''Test updating delivery settings fails because we don't have
a mobile number on the account'''
self.assertRaises(TwythonError, self.api.update_delivery_service,
device='none')
def test_update_profile(self):
'''Test updating profile succeeds'''
self.api.update_profile(include_entities='true')
def test_update_profile_colors(self):
'''Test updating profile colors succeeds'''
self.api.update_profile_colors(profile_background_color='3D3D3D')
示例4: open
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
for tweet in time:
print " \n User: " + tweet["user"]["name"]
print " \n Created: \n " + tweet["created_at"]
print " \n Text: \n " + tweet["text"]
# In[11]:
import json
with open("TL.json", "w") as archivo:
json.dump(time,archivo)
# In[15]:
followers = twitter.get_followers_list(screen_name="hmcuesta")
for follower in followers["users"]:
print " \n Usuario:" + follower["screen_name"]
print " \n Nombre:" + follower["name"]
print " \n Numero de twitts: " + str(follower["statuses_count"])
# In[18]:
tendencias = twitter.get_place_trends(id = 23424977 )
if tendencias:
for trend in tendencias[0].get("trends", []):
print "\n" + trend["name"]
示例5: str
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
log.write( "Looking for followers of " + username)
log.write("\n")
log.close()
followers_inserted = 0
num_api_calls = 0
there_are_more_followers = True
next_cursor = -1 #It'll be used for paginating the followers retrieved
#print "looking for followers of " + username
while followers_inserted < 200 and there_are_more_followers:
#we wanna insert at least 200 followers. That's our goal, but if there are not enough followers,
#we'll see later what to do. Please note,we don't want to store a hundreds of thousend of followers
try:
if num_api_calls >= 14: #Twitter allows us to do just 15 api calls every 15 min
time.sleep(900)
followers = twitter.get_followers_list(screen_name=username, count=200,cursor=next_cursor)
num_api_calls =1
else:
followers = twitter.get_followers_list(screen_name=username, count=200,cursor=next_cursor)
#print 'I have a new list of followers'
num_api_calls += 1
next_cursor = followers["next_cursor"]
#print "num followers = " + str(len(followers["users"]))
there_are_more_followers = len(followers["users"]) != 0
except: #I can't have their followers (private account, or another error)
followers = {}
followers["users"] = []
for follower in followers["users"]:
# Add their screen name to our followers list
if (follower["lang"] == "en" or follower["lang"] == "en-gb")\
and follower["statuses_count"] >= 400:
示例6: Twython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
twitter = Twython(APP_KEY, access_token=ACCESS_TOKEN)
followers_file = unicodecsv.writer(open(FILE_LOC, "wb"))
# Run basic program
if ADVANCED == 0:
# Write csv column headers
followers_file.writerow(["User Name", "Name", "ID", "Description", "Location", "URL"])
next_cursor = -1
p = 1
while next_cursor != 0:
print "Loading page", p, "of results from Twitter"
# Loop/set variables for each user in followers list
followers = twitter.get_followers_list(screen_name=USERNAME, count=200, cursor=next_cursor)
print "Writing page", p, "to csv file"
for result in followers["users"]:
screen_name = result["screen_name"]
name = result["name"]
tw_id = result["id"]
description = result["description"]
location = result["location"]
entities = result["entities"]
expanded_url = None
if "url" in entities:
entities_url = entities["url"]
entities_urls = entities_url["urls"]
for entities_result in entities_urls:
expanded_url = entities_result["expanded_url"]
示例7: TwythonAPITestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
#.........这里部分代码省略.........
"""Test returning incoming friendship ids succeeds"""
self.api.get_incoming_friendship_ids()
def test_get_outgoing_friendship_ids(self):
"""Test returning outgoing friendship ids succeeds"""
self.api.get_outgoing_friendship_ids()
def test_create_friendship(self):
"""Test creating a friendship succeeds"""
self.api.create_friendship(screen_name='justinbieber')
def test_destroy_friendship(self):
"""Test destroying a friendship succeeds"""
self.api.destroy_friendship(screen_name='justinbieber')
def test_update_friendship(self):
"""Test updating friendships succeeds"""
self.api.update_friendship(screen_name=protected_twitter_1,
retweets='true')
self.api.update_friendship(screen_name=protected_twitter_1,
retweets=False)
def test_show_friendships(self):
"""Test showing specific friendship succeeds"""
self.api.show_friendship(target_screen_name=protected_twitter_1)
def test_get_friends_list(self):
"""Test getting list of users authenticated user then random user is
following succeeds"""
self.api.get_friends_list()
self.api.get_friends_list(screen_name='twitter')
def test_get_followers_list(self):
"""Test getting list of users authenticated user then random user are
followed by succeeds"""
self.api.get_followers_list()
self.api.get_followers_list(screen_name='twitter')
# Users
def test_get_account_settings(self):
"""Test getting the authenticated user account settings succeeds"""
self.api.get_account_settings()
def test_verify_credentials(self):
"""Test representation of the authenticated user call succeeds"""
self.api.verify_credentials()
def test_update_account_settings(self):
"""Test updating a user account settings succeeds"""
self.api.update_account_settings(lang='en')
def test_update_delivery_service(self):
"""Test updating delivery settings fails because we don't have
a mobile number on the account"""
self.assertRaises(TwythonError, self.api.update_delivery_service,
device='none')
def test_update_profile(self):
"""Test updating profile succeeds"""
self.api.update_profile(include_entities='true')
def test_update_profile_colors(self):
"""Test updating profile colors succeeds"""
self.api.update_profile_colors(profile_background_color='3D3D3D')
示例8: TwythonEndpointsTestCase
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
#.........这里部分代码省略.........
@unittest.skip('skipping non-updated test')
def test_create_friendship(self):
"""Test creating a friendship succeeds"""
self.api.create_friendship(screen_name='justinbieber')
@unittest.skip('skipping non-updated test')
def test_destroy_friendship(self):
"""Test destroying a friendship succeeds"""
self.api.destroy_friendship(screen_name='justinbieber')
@unittest.skip('skipping non-updated test')
def test_update_friendship(self):
"""Test updating friendships succeeds"""
self.api.update_friendship(screen_name=protected_twitter_1,
retweets='true')
self.api.update_friendship(screen_name=protected_twitter_1,
retweets=False)
@unittest.skip('skipping non-updated test')
def test_show_friendships(self):
"""Test showing specific friendship succeeds"""
self.api.show_friendship(target_screen_name=protected_twitter_1)
@unittest.skip('skipping non-updated test')
def test_get_friends_list(self):
"""Test getting list of users authenticated user then random user is
following succeeds"""
self.api.get_friends_list()
self.api.get_friends_list(screen_name='twitter')
@unittest.skip('skipping non-updated test')
def test_get_followers_list(self):
"""Test getting list of users authenticated user then random user are
followed by succeeds"""
self.api.get_followers_list()
self.api.get_followers_list(screen_name='twitter')
# Users
@unittest.skip('skipping non-updated test')
def test_get_account_settings(self):
"""Test getting the authenticated user account settings succeeds"""
self.api.get_account_settings()
@unittest.skip('skipping non-updated test')
def test_verify_credentials(self):
"""Test representation of the authenticated user call succeeds"""
self.api.verify_credentials()
@unittest.skip('skipping non-updated test')
def test_update_account_settings(self):
"""Test updating a user account settings succeeds"""
self.api.update_account_settings(lang='en')
@unittest.skip('skipping non-updated test')
def test_update_delivery_service(self):
"""Test updating delivery settings fails because we don't have
a mobile number on the account"""
self.assertRaises(TwythonError, self.api.update_delivery_service,
device='none')
@unittest.skip('skipping non-updated test')
def test_update_profile(self):
"""Test updating profile succeeds"""
self.api.update_profile(include_entities='true')
示例9: print
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import get_followers_list [as 别名]
tweets = twitter.get_home_timeline(count=1)
for tweet in tweets:
print(tweet['text'])
print
print "My Settings"
print "==========="
settings = twitter.get_account_settings()
#print settings
print "I am @%s" % settings['screen_name']
print
print "My friends"
print "=========="
list = twitter.get_friends_list()
for friend in list['users']:
print "I follow user @%s, name %s, id %d" % (
friend['screen_name'], friend['name'], friend['id'])
print
print "My followers"
print "============"
list = twitter.get_followers_list()
for friend in list['users']:
print "User @%s, name %s, id %d is following me" % (
friend['screen_name'], friend['name'], friend['id'])
#print friend