DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

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

Collapse
 
zeguil profile image
José Guilherme • Edited on

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