Ashley (ashley_y) wrote in lj_nifty,

Friends Change Notification

Ah, the joys of the dot-file. Intended to provide "friends" information in a format suitable for making graphs, it's an excellent way for a software program to find out anyone's "friends" connections even if they've asked to hide their "friend of" list. No authentication is needed, either.

I created a simple script to output the friends list of any person. I call it ljfriends:

DOTFILE=`mktemp -t ljfriends`
curl -s "$" > $DOTFILE
grep -q digraph $DOTFILE || exit 1
FROMS=`mktemp -t ljfriends`
cat $DOTFILE | sed -n -e 's/^ *"\(.*\)"->"'$1'"/\1/ p' | sort -u > $FROMS
TOS=`mktemp -t ljfriends`
cat $DOTFILE | sed -n -e 's/^ *"'$1'"->"\(.*\)"/\1/ p' | sort -u > $TOS
#diff -a -U 0 $FROMS $TOS | sed -n -e '/^[-+][^-+]/ p' | sort
#diff -a $FROMS $TOS | sed -n -e '/^[<>]/ p' | sort
(diff -a -U 10000 $FROMS $TOS && sed -e 's/^/ /' $FROMS) | sed -n -e 's/^\([-+ ]\)\([^-+]\)/\1 \2/ p' | tr '+-' '><'

This works for communities and RSS feeds too: AFAIK it's the only way to find out who's reading a feed.

Now some people are only really interested in when their "friend of" list changes, which obviously means a much simpler script than the one above. But I'm interested in my own changes to my own "friends" list as well, so I put them all in. As you can see, there are a couple of other commented-out output options included, but this is the one I use.

So to receive notifications of changes to this list, I set up ljfriends together with another script on my ISP, which I call ljdiff:

touch $1.ljf
mv $1.ljf $1.old.ljf
./ljfriends $1 > $1.ljf || exit
diff -U 0 $1.old.ljf $1.ljf > $1.diff.ljf ||
 (m4 -DUSER=$1 ljfheadermail.m4 ; sed -n -e '/^[-+ ][^-+]/ p' $1.diff.ljf) | /usr/sbin/sendmail -t
rm $1.old.ljf

And this is its helper file ljfheadermail.m4: be sure to have an extra newline at the end of it, and change the "From" and "To" headers appropriately:

From: LJF Automailer <SENDER>
Subject: USER Friends Change

When ljdiff is called, it compares the list to the previous list, and mails me the change if there are any. I then use cron to run ljdiff every two hours:

0 0-23/2 * * *  nice $HOME/ljdiff ashley_y

Note the first time it's run, it mails you the entire list. You'll soon figure out what the changes mean if you're not familiar with "unified diff" output. And the way I've written it, you can monitor several different journals if you have them, just put a line for each journal in your crontab file.

Update: disabled now.

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded