↓ Skip to main content
  1. Home projects/

Following-of-following monitor

··

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.
The script fetches the followed accounts and their follows, saves dated JSON snapshots, compares the newest with the previous one and writes a text report.fetch accountsI followfetch the accountseach of them followsJSON snapshotfolder named by datecompare newest withprevious snapshottext reportadded, removed per accountlocal cacheuser ID to namerate limits: a user's list is refetched only if the saved copy is older than 3 hours, the first list once a day
From the follow lists to the text report

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.

Related