#!/usr/bin/perl # # blogpost_wp.pl # # post to a WordPress weblog (or any weblog using the MetaWeblog API # # usage: blogpost_wp.pl textfile # # where textfile contains the data to post. # The first line of textfile will be used as the Subject/Title of the # weblog entry. All subsequent lines go into the body. # # You must set the following configuration variables appropriately # (set them below, in the code, not here in the comments :-) # # $blogid = '1'; # $url = 'http://domain.com/'; # $path = $url . "path/to/wordpress/xmlrpc.php"; # $username = "YOUR_USERNAME"; # $password = "YOUR_PASSWORD"; use XMLRPC::Lite; our $DEBUG = 1; # CONFIGURATION # set the following variables appropriately for your configuration! our $blogid = '0'; our $url = 'http://domain.com/'; our $path = "path/to/wordpress/xmlrpc.php"; our $username = "YOUR_USERNAME"; our $password = "YOUR_PASSWORD"; MAIN: { my ($som, $call); my ($title, $body); my $server = $url . $path; my $call = 'metaWeblog.newPost'; # check for data file $textfile = $ARGV[0]; die "usage: $0 textfile\n" unless $textfile; die "cannot find data file $textfile\n" unless -f $textfile; # open and read datafile open (IN, "<$textfile"); @body = ; close (IN); # title: first line # body: remainder $title = $body[0]; shift @body; $body = join "", @body; # Debugging mode. Print values to scrteen. Do not post to weblog. if ($DEBUG) { print $call, $blogid, $username, $password, "\n"; print $title, "\n", $body, "\n"; print $url, "\n", $path, "\n", $server, "\n"; exit; } # Live mode ($DEBUG=0) post to weblog #Create a new rpc object. my $rpc = XMLRPC::Lite->new; $rpc->proxy($server); $som = $rpc->call($call, $blogid, $username, $password, { 'title' => $title, 'description' => $body, }, 1 # 1 = publish ); if ($som->fault) { print "[", $som->faultcode, "] ", $som->faultstring, "\n"; } }