DEV Community

Hammad-1
Hammad-1

Posted on

Get user followed/unfollowed count of last 24 hours from Twitter using Tweepy with python.

How can I get user followed/unfollowed count of last 24 hours from Twitter using Tweepy with python. I have essential access of twitter api v2. I have read the tweepy documentation but there is no query of filter follow/unfollow count from last 24 hours.

Top comments (1)

Collapse
 
zeguil profile image
José Guilherme • Edited

create a database with sqlalchemy with fields id, user_id, date, username (optional)

def new_follow(client, session):
     followers= client.get_users_followers(id=your_id)
     for follower in followers[0]:
     # checks if the user_id already exists in the database
         query = session.query(Follower ).filter_by(user_id=follower .id).first()
         if query:
    #  If it already exists, ignore it
             pass
         else:
    # If it doesn't exist in the database you save
             new_follower = Follower (user_id=str(follower .id), date=str(date.today())
             session.add(new_follower)
             session.commit()
Enter fullscreen mode Exit fullscreen mode

now to know how many people followed you in the last 24 hours just make a new function that makes a query in the database filtering by the date