![]() | You are viewing Log in Create a LiveJournal Account Learn more | Explore LJ: Life Entertainment Music Culture News & Politics Technology |
None of Them Knew They Were RobotsRecent Entries | ||
|
|
You are viewing the most recent 5 entries December 16th, 2003October 20th, 2003October 9th, 2003: Fibonacci They're writing Fibonacci programs over in the perl community... here is my -e contribution: perl -le 's 220 1 12;1 while s e(\d+) (\d{1,4})$eqq[$& ].($1+$2)ee;print'You can adjust how many numbers you get back by changing the quantifer on the second \d... to get up to 10 digit numbers, change {1,4} to {1,10}, etc The above is ofcourse heavily inspired by the old classic prime number regexp, by Abigail: perl -wle 'print "Prime" if (1 x shift) =~ /^(?!(11+)\1+$)/'(give it a number as an argument) I like perl :) September 4th, 2003: LJ Scraping Exercise Inspired by My script tells you which LJ users you share the most interests with. #!/usr/bin/perl -w
$L=10; die " usage: ./lj_interesting.pl ljusername
This script will show you the $L LiveJournal users whom you share the most
interests with, and tell you what those interests are. It doesn't work as
well for really popular interests, as livejournal only shows the first 500
users with a given interest, but the less common interests are probably
more interesting anyway. This script is released in the public domain by
the author, phyxeld. (notcopyright) 2003\n" unless $ARGV[0]; crawl(@ARGV);
sub crawl {
my $user=shift;
warn "Searching for users who share interests with $user ...\n";
my @int=scrape($user,0); my $t=$#int+1;
for $int (@int) {
printf STDERR (qq"\x0d\x1b[K %3d%% [%-30s] request %d ".
q[of %d "%s"], (++$i/$t*100),('*'x($i/$t*30)),$i,$t,$int);
push @{$d{$_}},$int for (scrape($int,1));
}
print "\nUser '$_' has ",$#{$d{$_}}+1," common interests:\n ",
join(', ',@{$d{$_}}),"\n" for (grep { !m/$user/ && 0<$L--}
sort {scalar @{$d{$b}}<=>scalar @{$d{$a}}} keys %d)
}
sub scrape { # scrape can do two things: @interests = scrape(user,0)
my ($q,$w)=@_; my @r=(); # @users = scrape(interest,1)
$re=$w?qr[rinfo\.bml\?user=([\w+]+)']:qr[sts\.bml\?int=([\w+]+)'];
my $u=$w?'interests.bml?int=':'userinfo.bml?user='; push @r, (m/$re/g)
for qx[curl "http://www.livejournal.com/$u$q" 2>/dev/null]; return @r;
}Naturally, the more interests you have listed, the better your results will be... and the longer the script will take to run (so a visual progress bar is displayed while the script works). The added load on LJ could potentially get heavy if a lot of people ran this; there is one HTTP request sent out for each of your interests, plus one for your userinfo page. If this becomes a problem for LJ (I doubt it will), then I'll take it down. Due to my extreme laziness, I'm fetching the pages with curl, so you'll need that installed if you want to try this out. (Or replace the single occurance of the word curl in the source with wget -O -) If anyone in ( Sample Output ) Current Music: Haujobb - Sinus Problem August 17th, 2003 |
|