Use this is code snippet :
user = api.get_user('xxxx')
print(user.followers_count)
for i in user.friends():
print(i.screen_name)
result for follower count is 700
but why when looping all data only show 21 row data?
Whilst getting the names of all followers of a user is possible you are likely to get banned from exceeding rate limits quickly.
The following code will tell you how many followers a user has and then list all the username of the people who follow the user.
username = 'keely_bro'
userID = api.get_user(username)
print('User is followed by ' + str(userID.followers_count) + ' people')
print('usernames of followers: ')
for allFollowers in tweepy.Cursor(api.followers_ids, screen_name=username).pages():
followerNames = [userID.screen_name for userID in api.lookup_users(allFollowers)]
for follow in followerNames:
print(follow)
Related
I want to search the whole timeline of a specific user for a particular query
I tried setting the .items() to the total number of tweets in the user profile
but I'm not getting any results back .. any idea on how to solve this issue?
username="No_Rumors"
t =" from:No_Rumors"
z= "أمين رابطة العالم الإسلامي يقرع جرس الكنيسة النصرانية"
no_of_tweets = api.get_user(screen_name=username).statuses_count
query=z+t
t = tweepy.Cursor(api.search,q=query).items(no_of_tweets)
for tweet in t:
print(tweet.text)
I'm trying to fetch Tweets from multiple Twitter accounts and then create a database with the TWEETS and the source of the TWEET " user name " by using the following code
posts = api.user_timeline(screen_name = 'AlArabiya_Brk', count = 100 , lang =
"ar",tweet_mode="extended")
df = pd.DataFrame([tweet.full_text for tweet in posts], columns = [ 'Tweets'])
but I have a question: how can I add more than one account? I tried doing:
posts = api.user_timeline(screen_name = ['AlArabiya_Brk','AJABreaking'], count = 100
,lang ="ar",tweet_mode="extended")
but didn't get the desired output
You'll need to make multiple calls with that method.
That API endpoint only allows a single screen name input.
I want to create a network graph of followers and followee of a list of over 500 Twitter users and for that, I am storing followers list and followee list of every user in user_list. I tried this code but it took too long to execute (it's been >18hrs) and at the end gave an error that I pasted here: https://pastebin.com/dgBgGN6M
user_list = []
for user in unique_creators:
ff_list = []
followers = []
for follower in tweepy.Cursor(api.followers, screen_name=user, count=1000).items():
followers.append(follower.screen_name)
friends = []
for friend in tweepy.Cursor(api.friends, screen_name=user, count=1000).items():
friends.append(friend.screen_name)
ff_list = [followers, friends]
user_list.append(ff_list)
Here unique_creators is the list of screen_names of Twitter users. Can someone please tell if I am doing something wrong?
I am using two slack API's, users.list() and users.getPresence(). I use users.list() to retrieve the user's names and IDs.
The users.getPresence() API takes the user ID as a parameter and only outputs their presence of 'active' or 'away' as it is shown here: https://api.slack.com/methods/users.getPresence
I tried taking the names I retrieved from users_list() and returning them along with the users_getPresence() API, but then I only got the list of names to repeat over each status.
client = slack.WebClient(API_KEY)
def users_list():
users_call = client.users_list()
users = users_call['members']
result = []
# loops for each user
for user in users:
uid = user['id']
name = user['profile']['real_name']
info = {"id": None, "name": None}
if users_call['ok']:
info['id'] = uid
info['name'] = name
result.append(info)
else:
return None
return result
def users_getPresence():
info = users_list()
users = []
for value in info:
uid = value['id']
users.append(uid)
presence = []
for user in users:
presence_call = client.users_getPresence(user = user)
if presence_call['ok']:
presence.append(presence_call['presence'])
else:
return None
return presence
Right now, the two API's have separate outputs, where users.list() returns ID and name while users.getPresence() returns presence.
How can I return the user's name and their status together?
Here is an updated version of your 2nd function that returns the list of all users with their presence status. Notice that I also added a sleep so you do not violate the rate limit of max 50 calls per minute.
def users_getPresence():
users = users_list()
for user in users:
presence_call = client.users_getPresence(user = user['id'])
sleep(1.2)
if presence_call['ok']:
user['presence'] = presence_call['presence']
else:
user['presence'] = None
return users
I also saw a couple of issues with your first function. Mainly checking for ok in the loop does not work, because if the method fails it will not contain any users and your script will fail before it reached the ok check.
I'm looking to retrieve the followers on some account with more than 5000 followers.
I've seen in a other topic than it's easier to proceed by page then by items per page. (link : tweepy count limited to 200?)
Once it reads all the id, it must check on the profile description if there is a element of a list i created before.
here's my previous code (note op, without using the api.followers):
for element in liste2:
print element
resultats = api.search_users(q=element, count=5000)
for user in resultats:
print user.id
i = 0;
user = api.get_user(user.id)
print user.name
while (i != 4):
if (user.description.find(liste1[i])!= 1):
print user.name + " valide"
i = 4;
statuses = api.user_timeline(id = user.id, count = 20\
0)
The counter doesn't work that's why i want to switch for api.followers witch seems to be more nice.
Thanks for reading