Perl programmer for hire: download my resume (PDF).
John Bokma Perl
freelance Perl programmer

Ping your blog via XML-RPC with Perl

Pong | 10 comments

The following Perl program connects to several update services to let them know that the your site or blog has been updated. The program uses XML-RPC to call the remote weblogUpdates.ping method of each update service with the name and URL of your site or blog as parameters. You can easily extend the list of update services that are used by the program if required so.

#!/usr/bin/perl
#
# rpcping.pl - Ping your blog with update services
#
# © Copyright, 2006 by John Bokma, http://johnbokma.com/
# License: The Artistic License
#
# $Id$ 

use strict;
use warnings;

use XMLRPC::Lite;

sub print_usage_and_exit {

    print <<USAGE;
usage: rpcping.pl "YOUR WEBLOG NAME" URL
USAGE

    exit;
}

@ARGV == 2 or print_usage_and_exit;
my ( $blog_name, $blog_url ) = @ARGV;

my @services = (

    # See http://codex.wordpress.org/Update_Services for
    # a more comprehensive list.
    'Google'         => 'http://blogsearch.google.com/ping/RPC2',
    'Weblogs.com'    => 'http://rpc.weblogs.com/RPC2',
    'Feed Burner'    => 'http://ping.feedburner.com/',
    'Moreover'       => 'http://api.moreover.com/RPC2',
    'Syndic8'        => 'http://ping.syndic8.com/xmlrpc.php' ,
    'BlogRolling'    => 'http://rpc.blogrolling.com/pinger/',
    'Technorati'     => 'http://rpc.technorati.com/rpc/ping' ,
    'BulkFeeds'      => 'http://bulkfeeds.net/rpc',
    'BlogFlux'       => 'http://pinger.blogflux.com/rpc/',
    'Ping-o-Matic!'  => 'http://rpc.pingomatic.com/',
    'NewsGator'      => 'http://services.newsgator.com/ngws/xmlrpcping.aspx',
    'Blog People'    => 'http://www.blogpeople.net/servlet/weblogUpdates',
    'Howly Cow Dude' => 'http://www.holycowdude.com/rpc/ping/',
    'Blog Update'    => 'http://blogupdate.org/ping/',
    'FeedSky'        => 'http://www.feedsky.com/api/RPC2',
);

while ( my ( $service_name, $rpc_endpoint ) = splice @services, 0, 2 ) {

    my $xmlrpc = XMLRPC::Lite->proxy( $rpc_endpoint );
    my $call;
    eval {
        $call = $xmlrpc->call( 'weblogUpdates.ping',
            $blog_name, $blog_url );
    };
    if ( $@ ) {

        chomp $@;
        warn "Ping '$service_name' failed: '$@'\n";
        next;
    }

    unless ( defined $call ) {

        warn "Ping '$service_name' failed for an unknown reason\n";
        next;
    }

    if ( $call->fault ) {

        chomp( my $message = $call->faultstring );
        warn "Ping '$service_name' failed: '$message'\n";
        next;
    }

    my $result = $call->result;
    if ( $result->{ flerror } ) {

        warn "Ping '$service_name' returned the following error: '",
            $result->{ message }, "'\n";
        next;
    }

    print "Ping '$service_name' returned: '$result->{ message }'\n";
}

Examples of program usage and output:

rpcping.pl "A Perl programmer in Mexico" http://johnbokma.com/mexit/
Ping 'Weblogs.com' returned: 'Thanks for the ping.'
Ping 'Feed Burner' returned: 'Ok'
Ping 'Feedster' returned: 'Thanks for the ping.'
Ping 'Blo.gs' returned the following error: 'Weblog already updated recently.'
Ping 'Syndic8' returned: 'Thanks for pinging Syndic8'
Ping 'BlogRolling' failed: 'Minimum time between pings not reached. Go have a
martini and try again in a bit.'
Ping 'Technorati' returned: 'Thanks for the ping'
Ping 'PubSub.com' returned: 'Ping Received.'

Blog Ping related

Please post a comment | read 10 comments, latest by budowa domów | RSS feed