Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Friday April 30, 2004
04:07 PM

Tracking LiveJournal "Friend of"

[ #18566 ]

LiveJournal is pretty cool---they have 53kr33t URLs to get information so I do not have to screen scrape.

In this case, I want to see who has added a user as their friend. I store that list and when I check again, I flag the new entries.

#!/usr/bin/perl -w
use strict;
use File::Spec::Functions;
use LWP::Simple qw(get);
my $user = $ARGV[0] || $ENV{LJ_USER} || die "No user named!\n";
my $data = get( "$user" );
my @friends = $data =~ m|^<\s+(\w+)$|gm;
my $Counter     = $ENV{LJ_FRIENDS_DB}  ||
    catfile( $ENV{HOME}, ".lj_friends_$user" );
dbmopen my %hash, $Counter, 0640 or die $!;
my $count = 1;
foreach my $friend ( @friends )
    $hash{ $friend }++;
    printf "%3d: %-15s", $count++, $friend;
    print "\t<--- NEW" if $hash{ $friend } == 1;
    print "\n";

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.