Skip to content

Instantly share code, notes, and snippets.

@mahm
Created January 30, 2014 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahm/8703118 to your computer and use it in GitHub Desktop.
Save mahm/8703118 to your computer and use it in GitHub Desktop.
rubypressでWordPressの記事一覧を取得する
pry(main)> wp.getPosts(filter: {order: 'desc'}).first
=> {"post_id"=>"5904",
"post_title"=>"モバイルアプリ向けUIフレームワークionicがSassで作られている&AngularJSに最適化されていて俺得すぎる",
"post_date"=>
#<XMLRPC::DateTime:0x007fb3988f0068
@day=29,
@hour=18,
@min=32,
@month=1,
@sec=21,
@year=2014>,
"post_date_gmt"=>
#<XMLRPC::DateTime:0x007fb39a00edd0
@day=29,
@hour=9,
@min=32,
@month=1,
@sec=21,
@year=2014>,
"post_modified"=>
#<XMLRPC::DateTime:0x007fb39a062f98
@day=29,
@hour=18,
@min=32,
@month=1,
@sec=21,
@year=2014>,
"post_modified_gmt"=>
#<XMLRPC::DateTime:0x007fb39a070cb0
@day=29,
@hour=9,
@min=32,
@month=1,
@sec=21,
@year=2014>,
"post_status"=>"publish",
"post_type"=>"post",
"post_name"=>"ionic",
"post_author"=>"1",
"post_password"=>"",
"post_excerpt"=>"",
"post_content"=>
"HTML5でモバイルアプリを作るなら、UIは<a href=\"http://ionicframework.com/\">ionic</a>で決まりなのでは!と思えるぐらい良いライブラリです。AngularJS&Sass派の人はぜひ使って
"post_parent"=>"0",
"post_mime_type"=>"",
"link"=>"http://blog.mah-lab.com/2014/01/29/ionic/",
"guid"=>"http://blog.mah-lab.com/?p=5904",
"menu_order"=>0,
"comment_status"=>"closed",
"ping_status"=>"closed",
"sticky"=>false,
"post_thumbnail"=>
{"attachment_id"=>"5905",
"date_created_gmt"=>
#<XMLRPC::DateTime:0x007fb3991575a8
@day=29,
@hour=8,
@min=27,
@month=1,
@sec=59,
@year=2014>,
"parent"=>5904,
"link"=>
"http://blog-mah-lab.s3.amazonaws.com/2014/01/Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework.png",
"title"=>"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework",
"caption"=>"",
"description"=>"",
"metadata"=>
{"width"=>2892,
"height"=>916,
"file"=>"2014/01/Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework.png",
"sizes"=>
{"thumbnail"=>
{"file"=>
"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-150x150.png",
"width"=>150,
"height"=>150,
"mime-type"=>"image/png"},
"medium"=>
{"file"=>
"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-300x95.png",
"width"=>300,
"height"=>95,
"mime-type"=>"image/png"},
"large"=>
{"file"=>
"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-1024x324.png",
"width"=>1024,
"height"=>324,
"mime-type"=>"image/png"},
"gallery-large"=>
{"file"=>
"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-870x400.png",
"width"=>870,
"height"=>400,
"mime-type"=>"image/png"},
"featured_post"=>
{"file"=>
"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-400x250.png",
"width"=>400,
"height"=>250,
"mime-type"=>"image/png"},
"standard"=>
{"file"=>
"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-700x300.png",
"width"=>700,
"height"=>300,
"mime-type"=>"image/png"},
"small"=>
{"file"=>
"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-194x150.png",
"width"=>194,
"height"=>150,
"mime-type"=>"image/png"},
"mini"=>
{"file"=>"Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-80x80.png",
"width"=>80,
"height"=>80,
"mime-type"=>"image/png"}},
"image_meta"=>
{"aperture"=>0,
"credit"=>"",
"camera"=>"",
"caption"=>"",
"created_timestamp"=>0,
"copyright"=>"",
"focal_length"=>0,
"iso"=>0,
"shutter_speed"=>0,
"title"=>""}},
"thumbnail"=>
"http://blog-mah-lab.s3.amazonaws.com/2014/01/Ionic__Advanced_HTML5_Hybrid_Mobile_App_Framework-150x150.png"},
"post_format"=>"standard",
"terms"=>
[{"term_id"=>"532",
"name"=>"JavaScript",
"slug"=>"javascript",
"term_group"=>"0",
"term_taxonomy_id"=>"552",
"taxonomy"=>"post_tag",
"description"=>"",
"parent"=>"0",
"count"=>4,
"filter"=>"raw"},
{"term_id"=>"271",
"name"=>"UI",
"slug"=>"ui",
"term_group"=>"0",
"term_taxonomy_id"=>"618",
"taxonomy"=>"category",
"description"=>"",
"parent"=>"0",
"count"=>7,
"filter"=>"raw"},
{"term_id"=>"241",
"name"=>"デザイン",
"slug"=>"%e3%83%87%e3%82%b6%e3%82%a4%e3%83%b3",
"term_group"=>"0",
"term_taxonomy_id"=>"241",
"taxonomy"=>"post_tag",
"description"=>"",
"parent"=>"0",
"count"=>12,
"filter"=>"raw"}],
"custom_fields"=>
[{"id"=>"13267", "key"=>"bluth_facebook_status", "value"=>""},
{"id"=>"13269", "key"=>"bluth_google_status", "value"=>""},
{"id"=>"13264", "key"=>"bluth_post_layout", "value"=>"right_side"},
{"id"=>"13266", "key"=>"bluth_post_left_sidebar", "value"=>"sidebar_left"},
{"id"=>"13265",
"key"=>"bluth_post_right_sidebar",
"value"=>"sidebar_right"},
{"id"=>"13268", "key"=>"bluth_twitter_status", "value"=>""},
{"id"=>"13270", "key"=>"wpb_post_views_count", "value"=>"18"}]}
require 'rubypress'
wp = Rubypress::Client.new(
host: 'blog.mah-lab.com',
username: '', # WordPress username
password: '' # WordPress password
)
posts = wp.getPosts(filter: {number: 200}).map do |post|
{
title: post['post_title'],
posted_at: post['post_date'].to_date.strftime('%Y-%m-%d'),
terms: post['terms'].map{|t| t['name']}.join(', '),
link: post['link']
}
end
posts.each do |post|
puts %Q("#{post[:title]}","#{post[:posted_at]}","#{post[:terms]}","#{post[:link]}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment