#!/usr/local/bin/perl

use WWW::Mechanize;

use constant USERNAME => 'friendster@crystalflame.net';
use constant PASSWORD => 'lemmein';

use constant FETCH => 0;
use constant DATA_FRIENDSTER => '/etc/mail/filster/data/friendster';
use constant USERS_FRIENDSTER => '/etc/mail/filster/users/friendster';
use constant PARSE => 0;

my $args = join ' ', @ARGV;
my $agent = WWW::Mechanize->new( );

my %users;
use Storable qw(lock_retrieve); %users = %{ lock_retrieve &USERS_FRIENDSTER };

my $content; if (!exists $users{} || &FETCH || $args =~ /fetch/) {
	$agent->get('http://www.friendster.com/');
	my $timeout; while ($agent->content =~ /login\.jsp/) {
	    if (++$timeout > 1) { $timeout = -1; last }
	    $agent->follow_link( url_regex => qr/login\.jsp/ );
	    $agent->submit_form(
		form_number => 1,
		fields => { email => &USERNAME, password => &PASSWORD, remember => 'yes' },
	    );
	}; die "Login failed" if $agent->content =~ /login\.jsp/;

	$agent->follow_link( url_regex => qr/usersearch\.jsp/ ) or die "User search not found";

} else {
}

use Storable qw(lock_nstore); lock_nstore \%users, &USERS_FRIENDSTER;

print join "\n", values %users;

