anitasp
anitasp

Reputation: 419

make a list from followers screen name tweepy

I am trying to make a list from my Twitter followers with the code:

users = tweepy.Cursor(api.followers).items()
l=[]
for user in users:
    l.append(user.screen_name)
    time.sleep(1)

The result of l is an empty list. Why?

Upvotes: 0

Views: 1165

Answers (1)

yohohosilver
yohohosilver

Reputation: 367

It seems with the limited information at hand that you are either not authenticated or don't have any followers. There are a million other things that could be wrong but without the whole program, it is impossible to deduce what.

For efficiency & simplicity why not run:

    my_followers = []
    for follower in tweepy.Cursor(api.followers).items():
     my_followers.append(follower.screen_name)
     time.sleep(1)

Note: PEP 8 Recommends you "Never use the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), or 'I' (uppercase letter eye) as single character variable names."

Update: To get the user id you could do something like:

     my_followers = []
     for follower in tweepy.Cursor(api.followers).items():
       user_key = [follower.screen_name,follower.user_id]
       my_followers.append(user_key)                                        
       time.sleep(1)

This way allows you to save both the User Id and Name in an array together. A perhaps, better way, would be to make these dictionary items depending on what you intend to do with the data.

Upvotes: 1

Related Questions