Created
June 17, 2011 08:00
-
-
Save gasi/1031047 to your computer and use it in GitHub Desktop.
Track Twitter Unfollowers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Track Twitter Unfollowers | |
# | |
# Run script daily using crontab and TextMate as follows: | |
# $ mate -w | crontab | |
# …paste `* */6 * * * /path/to/twitter-changes.sh` | |
# | |
# Adapted to Mac OS X from original script by Samuel Alba: | |
# http://shad.cc/how-to-know-all-of-your-unfollowers-on-twitte | |
# | |
# Mac OS X `readlink -f` workaround from Stack Overflow: | |
# http://stackoverflow.com/questions/1055671/1116890#1116890 | |
readlink2() { | |
TARGET_FILE=$1 | |
cd `dirname $TARGET_FILE` | |
TARGET_FILE=`basename $TARGET_FILE` | |
# Iterate down a (possible) chain of symlinks | |
while [ -L "$TARGET_FILE" ] | |
do | |
TARGET_FILE=`readlink $TARGET_FILE` | |
cd `dirname $TARGET_FILE` | |
TARGET_FILE=`basename $TARGET_FILE` | |
done | |
# Compute the canonicalized name by finding the physical path | |
# for the directory we're in and appending the target file. | |
PHYS_DIR=`pwd -P` | |
RESULT=$PHYS_DIR/$TARGET_FILE | |
echo $RESULT | |
} | |
# Config | |
SCREEN_NAME="gasi" | |
EMAIL="[email protected]" | |
( | |
cd $(dirname $(readlink2 $0)) | |
mv latest.log previous.log | |
curl -s -X GET "http://api.twitter.com/1/statuses/followers.xml?screen_name=${SCREEN_NAME}" | grep -E '^ <(screen_name|name)>' > latest.log | |
data=$(diff previous.log latest.log) | |
if [ ! -z "$data" ] ; then | |
# Removed from address because of Mac OS X error message: | |
# mail: illegal option -- a | |
echo "$data" | mail -s "[Twitter] Today’s Changes" $EMAIL | |
fi | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment