#!/usr/bin/perl -w ####################################################################### ### $Id: bloglines-0.02.txt,v 1.1 2004/02/08 08:46:09 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); $VERSION = '0.02'; 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 my $display = \&display; foreach $plugin (@plugins) { $plugin->can('display') and defined ($sub = $plugin->display) and $display = $sub and last; } # plugin: login my $login = \&login; foreach $plugin (@plugins) { $plugin->can('login') and defined ($sub = $plugin->login) and $login = $sub and last; } # plugin: parse_file my $parse_file = \&parse_file; foreach $plugin (@plugins) { $plugin->can('parse_file') and defined ($sub = $plugin->parse_file) and $parse_file = $sub and last; } # retrieve the entries my ($file, $list, $site) = &$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 ####################################################################### 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) = &$parse_file($file) or return; return ($file, $list, $site); } my ($res, $title); my $retry = 4; my $uri = "$DISPLAY_URL?".join('&', @query); my $login_succeeded = 0; while ($retry-- > 0) { $res = request($uri, $file) or warn("Can't request: $uri"), return; $title = $res->header('Title') || ""; if ($title =~ /My Blogs/) { $login_succeeded = 1; last; } &$login(); sleep(1); } $login_succeeded or warn("Can't login: $uri"), return; ($list, $site) = &$parse_file($file); return ($file, $list, $site); } 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; } 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; } sub parse_file { 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 (/^