Track a Twitter user's follower count over time. Produces a CSV with a timestamp and follower count at the time. Includes directions for setting up a cron job that runs the Ruby script using an RVM.
- Optional: If you want to regularly track someone's Twitter followers, you should run this on a remote machine that will never turn off. Using an Amazon EC2 box is a good option.
- Install RVM. Do not install RVM if you already use rbenv or a similar program.
- Create/register a new app on Twitter's app developer dashboard.
- Download/clone this repository. (
git clone [email protected]:joannaskao/tveitter-counter.git
)
First, let's set up the script.
- Create a RVM gemset. You will need a specify a gemset when you set up your cron job. (e.g.
rvm use 2.2.1@tveitter-counter --create
) - In
script.rb
, copy and paste your consumer key, consumer secret, access token and access secret from the app you created on the Twitter developer dashboard into lines 7-10. Don't share these values. - On line 25 of
script.rb
, replace path/to/output.csv with the location of where you want your data dumped. A path from your home folder is recommended (e.g. absolute file path). - If you don't want to track @aarontveit, you can specify another Twitter handle on line 13 of
script.rb
. - Replace the path in line 4 of
tveitter-counter-cron.sh
with whatrvm env --path -- 2.2.1@tveitter-counter
returns. - Replace the path in line 7 of
tveitter-counter-cron.sh
with a path to yourscript.rb
file. Absolute file paths are best. - Make sure that your .sh file is executable. Run
chmod 400 path/to/tveitter-counter-cron.sh
.
At this point, you should be able to run your shell script. You can test your work by running sh tveitter-counter-cron.sh
in the folder where your file is located.
If that works, we can move on to writing a cron job so that your machine automatically runs the script at a regular interval.
- To edit your list of cron jobs, run
crontab -e
from any directory on your machine. - You'll want to run your script approximately once every other minute or less frequently. The Twitter API restricts you to 15 calls every 15 minutes. Add
*/2 * * * * /path/to/twitter-tracker-cron.sh
to your crontab file with your specific path to thetwitter-tracker-cron.sh
file.
The project initially started as a way to track Aaron Tveit's rate of Twitter follower gain after he joined Twitter on August 27, 2015. But the script can be modified to track any other Twitter handle by just changing one line of code.