Lukas Z's Blog

Minimalist Twitter Follower Tracking

From the “what you can do with your own email-server”-department: Here is a minimalist way to track followers on Twitter.

Bascially, I wondered how much it would take to get a daily email that lists the people that have subscribed to and unsubscribed from my Twitter feed.

To give you an idea how little it takes, here’s the script that can be executed via crond every day:

#!/bin/bash
DIR="<SOME_DIRECTORY>"
SUBJECT="TWITTER-DIFF"
RECIPIENT="lz"
EMAILMESSAGE="./msg.txt"
DATE=`date`
diff $DIR/followers.txt.prev $DIR/followers.txt > diff.txt
cp $DIR/followers.txt $DIR/followers.txt.prev
t followers @lukaszielinski > $DIR/followers.txt
echo -e "Twitter Followers $DATE\n\n" > $EMAILMESSAGE
echo -e "Diff:\n\n" >> $EMAILMESSAGE
cat diff.txt >> $EMAILMESSAGE
echo -e "\n\nFollowers:\n\n" >> $EMAILMESSAGE
cat $DIR/followers.txt >> $EMAILMESSAGE
mail -s "$SUBJECT" "$RECIPIENT" < $EMAILMESSAGE

Because I use sferik/t (line 9 above) to get the list of followers, this particular script requires ruby to run. A Twitter-API key is also required and can be obtained with a few clicks at twitter.com.

The nice thing about this ugly script is actually just the last line: Because “lz” is a user on the server a simple call of “mail” is all it takes to deliver the data. My mail-client delivers it to my desktop using IMAP.

The result isn’t pretty, but it works.

Of course with some work I can write all sorts of fancy analytics and information into my daily email. But I’ll leave this as an exercise for the so inclined reader. ;)

P.S.: You can follow me on Twitter.

Comments

Webmentions