#!/usr/bin/perl -w ####################################################################### ### $Id: bloglines-0.03.txt,v 1.1 2004/02/09 03:02:27 mate Exp $ ### package Bloglines; ####################################################################### # CONFIGURATION $LOGIN_EMAIL = ''; $LOGIN_PASS = ''; $DATA_DIR = './data'; $PLUGINS_DIR = './plugins'; # $DISPLAY_URL = 'http://www.bloglines.com/myblogs_display'; # $LOGIN_URL = 'http://www.bloglines.com/login'; # $UA_PROXY = 'http://my.proxy.server.domain.name:port/'; # $UA_PROXY_BYPASS = ['localhost','127.0.0.1']; # $UA_TIMEOUT = 60; # $UA_NAME = ""; # $DEBUG = 0; # CONFIGURATION ####################################################################### $|=1; use strict; use URI; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; use Getopt::Long; use vars qw($DATA_DIR $PLUGINS_DIR $LOGIN_EMAIL $LOGIN_PASS $DISPLAY_URL $LOGIN_URL $UA $UA_PROXY $UA_PROXY_BYPASS $UA_TIMEOUT $UA_NAME $DEBUG $VERSION @OPTIONS %OPTCTL $do_display $do_request $do_retrieve $do_login $do_parsefile); $VERSION = '0.03'; my ($plugin, $sub); my @plugins = _load_plugins($PLUGINS_DIR); exit unless GetOptions(\%OPTCTL, "folder=i", "all:s", "since=i", "local", @OPTIONS); $DISPLAY_URL ||= 'http://www.bloglines.com/myblogs_display'; $LOGIN_URL ||= 'http://www.bloglines.com/login'; $UA = LWP::UserAgent->new; $UA->agent(defined($UA_NAME) ? $UA_NAME : ""); $UA->timeout(defined($UA_TIMEOUT) ? $UA_TIMEOUT : 60); $UA->proxy(['http'], $UA_PROXY) if (defined $UA_PROXY); $UA->no_proxy($UA_PROXY_BYPASS) if (defined $UA_PROXY_BYPASS); $UA->env_proxy unless (defined($UA_PROXY) || defined($UA_PROXY_BYPASS)); $UA->cookie_jar(HTTP::Cookies->new(file => "$DATA_DIR/cookies", autosave => 1)); # plugin: display $do_display = \&display; foreach $plugin (@plugins) { $plugin->can('display') and defined ($sub = $plugin->display) and $do_display = $sub and last; } # plugin: retrieve $do_retrieve = \&retrieve; foreach $plugin (@plugins) { $plugin->can('retrieve') and defined ($sub = $plugin->retrieve) and $do_retrieve = $sub and last; } # plugin: request $do_request = \&request; foreach $plugin (@plugins) { $plugin->can('request') and defined ($sub = $plugin->request) and $do_request = $sub and last; } # plugin: login $do_login = \&login; foreach $plugin (@plugins) { $plugin->can('login') and defined ($sub = $plugin->login) and $do_login = $sub and last; } # plugin: parsefile $do_parsefile = \&parsefile; foreach $plugin (@plugins) { $plugin->can('parsefile') and defined ($sub = $plugin->parsefile) and $do_parsefile = $sub and last; } # retrieve the entries my ($file, $list, $site) = &$do_display(\%OPTCTL); # plugin: filter foreach $plugin (@plugins) { $plugin->can('filter') and $plugin->filter($file, $list, $site); } # plugin: teardown foreach $plugin (@plugins) { $plugin->can('teardown') and $plugin->teardown; } exit; # End of Main ####################################################################### # default subroutine sub display { my ($optref) = @_; my ($file, $list, $site, @query); if (exists $optref->{folder}) { $file = "$DATA_DIR/display".$optref->{folder}; push @query, 'folder='.$optref->{folder}; } if (exists $optref->{all}) { $file = "$DATA_DIR/displayall"; push @query, 'all='.$optref->{all}; } if (exists $optref->{since}) { push @query, 'since='.$optref->{since}; } return () unless (@query); if (exists $optref->{local}) { ($list, $site) = &$do_parsefile($file) or return; return ($file, $list, $site); } &$do_retrieve("$DISPLAY_URL?".join('&', @query), $file, 'Title:[\w\s\|]+My Blogs') or warn("Can't login"), return; ($list, $site) = &$do_parsefile($file); return ($file, $list, $site); } # default subroutine sub retrieve { my ($uri, $file, $header_re) = @_; my ($res); my $retry = 4; my $succeeded = 0; while ($retry-- > 0) { $res = &$do_request($uri, $file) or warn("Can't request: $uri"), return; if ($res->headers->as_string =~ /$header_re/) { $succeeded = 1; last; } &$do_login(); sleep(1); } return $succeeded; } # default subroutine sub request { my ($uri, $file) = @_; my $req = GET($uri); my $res = $UA->request($req, $file); warn "ua->request: $uri\n".$res->headers->as_string."\n" if $DEBUG; unless ($res->is_success) { warn $res->message."\n" if $DEBUG; return; } return $res; } # default subroutine sub login { my $uri = $LOGIN_URL; my $email = $LOGIN_EMAIL; my $password = $LOGIN_PASS; my $file = "$DATA_DIR/login"; my $req = POST($uri, [ email => $email, password => $password, r => '/myblogs' ], Referer => $uri ); my $res = $UA->request($req, $file); warn "ua->request: $uri\n".$res->headers->as_string."\n" if $DEBUG; return $res->header('Set-Cookie') ? 1 : 0; } # default subroutine sub parsefile { my ($file) = @_; my ($siteList, $list, $site, %sitehead); open(F, $file) or warn("Can't open $file: $!"), return; while () { s/\r//g if /\r/; next if /^$/; # # # if (/^