I wrote this small Python script against the Twitter API v2 (through tweepy) to answer one question: whom did the people I follow start or stop following?
- It fetches the list of accounts followed by one account, then, for each of those, the accounts they follow.
- Each list is saved as JSON in a folder named after the date.
- Every run compares the newest snapshot with the previous one and writes a plain-text report: for each followed account, who was added and who was removed.
- User IDs are turned into names through a local cache that is filled in from the API as needed.
To stay within the API rate limits, the script refetches a user’s list only when the saved copy is older than three hours, and the root list once a day.