Created
October 12, 2011 08:05
-
-
Save sawanoboly/1280578 to your computer and use it in GitHub Desktop.
Wordpress test tool. Create new post. Add comment at newest post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
## Wordpress test tool. | |
## Create new post. | |
## | |
## Reference: http://rcbth.com/2010/07/16/wordpress-posting-from-ruby-xmlrpc/ | |
require 'xmlrpc/client' | |
# Wordpress Setting | |
wp_server = '127.0.0.1' | |
wp_port = 80 | |
wp_user = 'admin' | |
wp_password = 'password' | |
# build a post | |
post = { | |
'title' => 'Post:' + Time.now.to_i.to_s, | |
'description' => 'The content of the post', | |
'mt_keywords' => ['a', 'list', 'of', 'tags'], | |
'categories' => ['a', 'list', 'of', 'categories'] | |
} | |
# initialize the connection | |
connection = XMLRPC::Client.new(wp_server, '/xmlrpc.php', wp_port) | |
# make the call to publish a new post | |
connection.call( | |
'metaWeblog.newPost', | |
1, | |
wp_user, | |
wp_password, | |
post, | |
true | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
## Wordpress test tool. | |
## Add comment at newest post. | |
## | |
## To continuous posting. | |
## edit wp-includes/comment.php | |
## comment out this line. // do_action( 'check_comment_flood' | |
## | |
require 'xmlrpc/client' | |
require 'net/http' | |
# Wordpress Setting | |
wp_server = '127.0.0.1' | |
wp_port = 80 | |
wp_user = 'admin' | |
wp_password = 'password' | |
# initialize the connection | |
connection = XMLRPC::Client.new(wp_server, '/xmlrpc.php', wp_port) | |
# get newest postid. | |
recent = connection.call( | |
'metaWeblog.getRecentPosts', | |
1, | |
wp_user, | |
wp_password, | |
1 | |
) | |
postid = recent[0]["postid"] | |
# create post data | |
postdata = { | |
'author' => 'commenter', | |
'email' => '[email protected]', | |
'url' => 'http://www.example.com', | |
'comment' => rand().to_s, | |
'submit' => 'Post Comment', | |
'comment_post_ID' => postid.to_s, | |
'comment_parent' => '0' | |
} | |
res = Net::HTTP.post_form(URI.parse("http://#{wp_server}:#{wp_port}/wp-comments-post.php"), postdata) | |
# p res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment