Dan Bornstein ([info]danfuzz) wrote,
@ 2006-03-13 11:02:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Private LJ <-> Luddite Impedence Matching Device
I'm not big into blog reading in general, so it's probably not too surprising that I find it a pain in the butt to run a separate app to read the few blogs that I do.

I recently switched to GMail for much of my mail, and that solved part of my problem, since it lets you add RSS feeds to it, where it will show you one headline in a little box above the main email content. Within a day or two, I've read enough headlines that I probably don't miss any postings.

Unfortunately, though, the GMail feature only works for public (non-authenticated) feeds. So, I took the time to write the script below. I run it (a couple times, for a couple different journals) in a cron job once a day and have it email the output to me if it's not empty. The idea is that, every day, it grabs some LJ user's atom feed both with and without authentication. Subtracting the non-authenticated stuff from the authenticated stuff leaves you with a list of private postings, and diffing that list with the same list from the last time you run it lets you know what's new.

Without further ado, lj-alert:
#!/bin/bash
#
# lj-alert <userid>

set -e

if [ "x$1" = "x" ]; then
echo "$0: no userid specified"
exit 1
fi

who="$1"
user='xxxxx' # your LJ userid here
passwd='xxxxx' # your LJ password here
url="http://${who}.livejournal.com/data/atom"

# set up prog to be the name of this script, including following symlinks
prog=`type -p $0` >/dev/null 2>&1
while [ -L "$prog" ]
do
newprog=`expr "\`/bin/ls -l "$prog"\`" : ".*$prog -> \(.*\)"`
expr "$newprog" : / >/dev/null || newprog="`dirname $prog`/$newprog"
prog="$newprog"
done
progDir="`dirname $prog`"
libDir="$progDir/../lib/lj-alert"

lastDiffFile="${libDir}/${who}-last.txt"
mkdir -p "$libDir"

tmpDir="/tmp/lj-$"
publicFile="${tmpDir}/public.txt"
privateFile="${tmpDir}/private.txt"
diffFile="${tmpDir}/diff.txt"
newFile="${tmpDir}/new-stuff.txt"

rm -rf "$tmpDir"
mkdir "$tmpDir"

if [ -r "${who}-public.txt" ]; then
cp "${who}-public.txt" "$publicFile"
else
curl --silent --output "$publicFile" "$url"
fi

if [ -r "${who}-private.txt" ]; then
cp "${who}-private.txt" "$privateFile"
else
curl --silent --output "$privateFile" --digest --user "${user}:${passwd}" \
"${url}?auth=digest"
fi

diff -U 0 "$publicFile" "$privateFile" | tail +3 | grep '^\+' | \
sed -e 's/^\+//g' > "$diffFile"
touch "$lastDiffFile"
diff -U 0 "$lastDiffFile" "$diffFile" | tail +3 | grep '^\+' | \
sed -e 's/^\+//g' > "$newFile"
cp "$diffFile" "$lastDiffFile"

awk '
/^ *<link.*href="[^"]*"/ {
match($0, /href="[^"]*"/);
link = substr($0, RSTART + 6, RLENGTH - 7);
printf("\n <%s>\n", link);
}
/^ *<title>/ {
title = $0;
gsub(/ *<\/?title>/, "", title);
printf(" %s\n", title);
}
' $newFile

rm -rf "$tmpDir"




(1 comment) - (Post a new comment)

Schweet
[info]jymdyer
2006-03-14 05:33 pm UTC (link)
=v= Ain't seen me some awk in quite a while.

(Reply to this)


(1 comment) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…