Xu Xiaodong avatar Xu Xiaodong committed 32f8dc6

initial commit

Comments (0)

Files changed (2)

+A simple client for WordPress.
+#!/usr/bin/env perl
+#
+# name:      blogpost, a simple cli client for wordpress
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2010 Feb 22
+# modified:  2011 May 08
+#
+
+use strict;
+use warnings;
+
+use XMLRPC::Lite;
+
+my $url    = 'http://linuxtoy.org/xmlrpc.php';
+my $client = XMLRPC::Lite->proxy($url);
+
+# wordpress account
+my $username = '';
+my $password = '';
+
+my $blogid  = 1;
+my $publish = 1;
+
+my $post_ref;
+$post_ref->{title}       = shift;    # post title
+$post_ref->{wp_slug}     = shift;    # post slug
+$post_ref->{mt_keywords} = shift;    # post tag
+
+my $category = shift;                # post category
+@{ $post_ref->{categories} } = split /, /, $category;
+
+my $content = shift;                 # post content
+open my $content_fh, '<', $content
+  or die "Can't open $content: $!\n";
+while (<$content_fh>) {
+  $post_ref->{description} .= $_;
+}
+close $content_fh;
+
+my $postid = shift;                  # post id
+my $new_post;
+my $edit_post;
+if ($postid) {
+  my $date = qx(date -u +%Y%m%dT%T);
+  $post_ref->{dateCreated} = $date;
+  $edit_post = $client->call( 'metaWeblog.editPost',
+    $postid, $username, $password, $post_ref, $publish );
+}
+else {
+  $new_post = $client->call( 'metaWeblog.newPost',
+    $blogid, $username, $password, $post_ref, $publish );
+}
+
+if ( $new_post or $edit_post ) {
+  print "Post success.\n";
+}
+else {
+  print "Post fail.\n";
+}
+
+# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=perl
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.