{"id":1487,"date":"2012-03-14T10:57:25","date_gmt":"2012-03-14T01:57:25","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=1487"},"modified":"2012-03-14T11:42:32","modified_gmt":"2012-03-14T02:42:32","slug":"python-xmlrpc%e3%81%a7wordpress%e3%81%ae%e8%a8%98%e4%ba%8b%e3%82%92%e4%b8%80%e6%8b%ac%e7%b7%a8%e9%9b%86%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/1487","title":{"rendered":"Python + XMLRPC\u3067WordPress\u306e\u8a18\u4e8b\u3092\u4e00\u62ec\u7de8\u96c6\u3057\u3066\u307f\u305f"},"content":{"rendered":"<p>\u6700\u8fd1xv6\u306e\u8a18\u4e8b\u3092\u305a\u3063\u3068\u66f8\u3044\u3066\u307e\u3059\u304c\u3001\u300cxv6\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30ea\u30fc\u30c7\u30a3\u30f3\u30b0 \u305d\u306e10\u300d\u307f\u305f\u3044\u306a\u30bf\u30a4\u30c8\u30eb\u306e\u4ed8\u3051\u65b9\u3092\u3057\u3066\u3066\u3001\u30bf\u30a4\u30c8\u30eb\u304b\u3089\u5f97\u3089\u308c\u308b\u60c5\u5831\u304c\u307b\u3068\u3093\u3069\u306a\u3044\u306e\u3067\u3001\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u5909\u66f4\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u73fe\u6642\u70b9\u3067\u305d\u306e40\u307e\u3067\u3042\u3063\u3066\u3001\u3044\u3063\u3053\u305a\u3064\u7ba1\u7406\u753b\u9762\u3067\u5909\u66f4\u3059\u308b\u306e\u306f\u3068\u3066\u3082\u3081\u3093\u3069\u304f\u3055\u3044\u306e\u3067\u3001WordPress\u306eXMLRPC\u6a5f\u80fd\u3092\u4f7f\u3063\u3066Python\u3067\u8a18\u4e8b\u3092\u4e00\u62ec\u7de8\u96c6\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u3068\u304d\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u3092\u516c\u958b\u3057\u307e\u3059\u3002<\/p>\n<p>\u3082\u306e\u51c4\u304f\u72b6\u6cc1\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u30b3\u30fc\u30c9\u306b\u5168\u304f\u6c4e\u7528\u6027\u304c\u306a\u3044\u3067\u3059\uff08\u3057\u304b\u3082\u4f7f\u3044\u6368\u3066\u306a\u306e\u3067\u304b\u306a\u308a\u9069\u5f53\u306b\u66f8\u304d\u307e\u3057\u305f\uff09\u304c\u3001Python\u304b\u3089WordPress\u306eXMLRPC\u6a5f\u80fd\u3092\u4f7f\u3046\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b<a href=\"https:\/\/github.com\/maxcutler\/python-wordpress-xmlrpc\" target=\"_blank\">python-wordpress-xmlrpc<\/a>\u306e\u4f7f\u3044\u65b9\u306e\u30b5\u30f3\u30d7\u30eb\u306b\u306a\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u300cxv6\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30ea\u30fc\u30c7\u30a3\u30f3\u30b0 \u305d\u306en\u300d\u3068\u3044\u3046\u30d1\u30bf\u30fc\u30f3\u306b\u5408\u81f4\u3059\u308b\u30bf\u30a4\u30c8\u30eb\u3092\u6301\u3064\u8a18\u4e8b\u306b\u5bfe\u3057\u3066\u3001\u30bf\u30a4\u30c8\u30eb\u3092\u300c[xv6 #n] (\u7ae0\u756a\u53f7) &#8211; (\u7ae0\u984c) &#8211; (\u7bc0\u984c\u3001\u3082\u3057\u3042\u308c\u3070\uff09\u300d\u3068\u3044\u3046\u5f62\u5f0f\u306b\u5909\u3048\u3001\u672c\u6587\u306e\u6700\u521d\u306b\u66f8\u304b\u308c\u3066\u3044\u308b\u3001\u7ae0\u756a\u53f7\u3001\u7ae0\u984c\u3001\u7bc0\u984c\u3092\u6d88\u53bb\u3059\u308b\u3001\u3068\u3044\u3046\u51e6\u7406\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u5143\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306f\u305d\u308c\u81ea\u4f53\u304c\u30de\u30ba\u30a4\u3068\u306f\u3044\u3048\u3001\u305d\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306f\u53b3\u5bc6\u306b\u5b88\u3063\u3066\u305f\u306e\u3067\u3001\u30b3\u30fc\u30c9\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u6e08\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u305f\u3060\u3001python-wordpress-xmlrpc\u306f\u5185\u90e8\u3067\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u8003\u616e\u3057\u3066\u306a\u3044\u3063\u307d\u3044\u306e\u3067\u3001\u8a18\u4e8b\u3092\u306a\u306b\u3082\u5909\u66f4\u305b\u305a\u306b\u66f4\u65b0\u3059\u308b\u3060\u3051\u3067\u3082\u516c\u958b\u65e5\u4ed8\u304c\u5909\u308f\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\uff08\u4f8b\u3048\u30709\u6642\u9593\u30d7\u30e9\u30b9\u3055\u308c\u308b\u3068\u304b\uff09\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">#! \/usr\/bin\/env python\r\n# -*- coding: utf8  -*-\r\n\r\nimport re\r\nfrom wordpress_xmlrpc import Client, WordPressPost\r\nfrom wordpress_xmlrpc.methods.posts import GetRecentPosts, EditPost\r\n\r\nwordpress = &quot;http:\/\/example.com\/xmlrpc.php&quot;\r\nuser = &quot;&quot;\r\npassword = &quot;&quot;\r\n\r\nwp = Client(wordpress, user, password)\r\nposts = wp.call(GetRecentPosts(50))\r\n\r\nre_title = re.compile(u'xv6\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30ea\u30fc\u30c7\u30a3\u30f3\u30b0 \u305d\u306e(?P&lt;number&gt;\\d+)')\r\nre_description = re.compile(u'^(?P&lt;basetitle&gt;.+)\\n\u30c6\u30ad\u30b9\u30c8\u306e', re.MULTILINE | re.DOTALL)\r\n\r\nfor post in posts:\r\n    match = re_title.match(post.title)\r\n    if match:\r\n        num = match.group('number')\r\n\r\n        match = re_description.search(post.description)\r\n        if match:\r\n            basetitle = match.group('basetitle')\r\n            re_editdesc = re.compile(u'%s\\n' % re.escape(basetitle), re.MULTILINE)\r\n            new_description = re_editdesc.sub(u'', post.description)\r\n            new_title = u'&#x5B;xv6 #%s] %s' % (num, ' - '.join(basetitle.split('\\n')))\r\n            \r\n            print 'Editing %s' % new_title\r\n            \r\n            post.title = new_title\r\n            post.description = new_description\r\n            wp.call(EditPost(post.id, post, True))\r\n            \r\n            print 'Edited.'\r\n            print<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1xv6\u306e\u8a18\u4e8b\u3092\u305a\u3063\u3068\u66f8\u3044\u3066\u307e\u3059\u304c\u3001\u300cxv6\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30ea\u30fc\u30c7\u30a3\u30f3\u30b0 \u305d\u306e10\u300d\u307f\u305f\u3044\u306a\u30bf\u30a4\u30c8\u30eb\u306e\u4ed8\u3051\u65b9\u3092\u3057\u3066\u3066\u3001\u30bf\u30a4\u30c8\u30eb\u304b\u3089\u5f97\u3089\u308c\u308b\u60c5\u5831\u304c\u307b\u3068\u3093\u3069\u306a\u3044\u306e\u3067\u3001\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u5909\u66f4\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u73fe\u6642\u70b9\u3067\u305d\u306e40\u307e\u3067\u3042\u3063\u3066\u3001\u3044\u3063\u3053\u305a\u3064\u7ba1\u7406\u753b\u9762\u3067\u5909\u66f4\u3059\u308b\u306e\u306f\u3068\u3066\u3082\u3081\u3093\u3069\u304f\u3055\u3044\u306e\u3067\u3001WordPress\u306eXMLRPC\u6a5f\u80fd\u3092\u4f7f\u3063\u3066Python\u3067\u8a18\u4e8b\u3092\u4e00\u62ec\u7de8\u96c6\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u3068\u304d\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u3092\u516c\u958b\u3057\u307e\u3059\u3002<\/p>\n<p>\u3082\u306e\u51c4\u304f\u72b6\u6cc1\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u30b3\u30fc\u30c9\u306b\u5168\u304f\u6c4e\u7528\u6027\u304c\u306a\u3044\u3067\u3059\uff08\u3057\u304b\u3082\u4f7f\u3044\u6368\u3066\u306a\u306e\u3067\u304b\u306a\u308a\u9069\u5f53\u306b\u66f8\u304d\u307e\u3057\u305f\uff09\u304c\u3001Python\u304b\u3089WordPress\u306eXMLRPC\u6a5f\u80fd\u3092\u4f7f\u3046\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b<a href=\"https:\/\/github.com\/maxcutler\/python-wordpress-xmlrpc\" target=\"_blank\">python-wordpress-xmlrpc<\/a>\u306e\u4f7f\u3044\u65b9\u306e\u30b5\u30f3\u30d7\u30eb\u306b\u306a\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u300cxv6\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30ea\u30fc\u30c7\u30a3\u30f3\u30b0 \u305d\u306en\u300d\u3068\u3044\u3046\u30d1\u30bf\u30fc\u30f3\u306b\u5408\u81f4\u3059\u308b\u30bf\u30a4\u30c8\u30eb\u3092\u6301\u3064\u8a18\u4e8b\u306b\u5bfe\u3057\u3066\u3001\u30bf\u30a4\u30c8\u30eb\u3092\u300c[xv6 #n] (\u7ae0\u756a\u53f7) &#8211; (\u7ae0\u984c) &#8211; (\u7bc0\u984c\u3001\u3082\u3057\u3042\u308c\u3070\uff09\u300d\u3068\u3044\u3046\u5f62\u5f0f\u306b\u5909\u3048\u3001\u672c\u6587\u306e\u6700\u521d\u306b\u66f8\u304b\u308c\u3066\u3044\u308b\u3001\u7ae0\u756a\u53f7\u3001\u7ae0\u984c\u3001\u7bc0\u984c\u3092\u6d88\u53bb\u3059\u308b\u3001\u3068\u3044\u3046\u51e6\u7406\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u5143\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306f\u305d\u308c\u81ea\u4f53\u304c\u30de\u30ba\u30a4\u3068\u306f\u3044\u3048\u3001\u305d\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306f\u53b3\u5bc6\u306b\u5b88\u3063\u3066\u305f\u306e\u3067\u3001\u30b3\u30fc\u30c9\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u6e08\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u305f\u3060\u3001python-wordpress-xmlrpc\u306f\u5185\u90e8\u3067\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u8003\u616e\u3057\u3066\u306a\u3044\u3063\u307d\u3044\u306e\u3067\u3001\u8a18\u4e8b\u3092\u306a\u306b\u3082\u5909\u66f4\u305b\u305a\u306b\u66f4\u65b0\u3059\u308b\u3060\u3051\u3067\u3082\u516c\u958b\u65e5\u4ed8\u304c\u5909\u308f\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\uff08\u4f8b\u3048\u30709\u6642\u9593\u30d7\u30e9\u30b9\u3055\u308c\u308b\u3068\u304b\uff09\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">#! \/usr\/bin\/env python\r\n# -*- coding: utf8  -*-\r\n\r\nimport re\r\nfrom wordpress_xmlrpc import Client, WordPressPost\r\nfrom wordpress_xmlrpc.methods.posts import GetRecentPosts, EditPost\r\n\r\nwordpress = &quot;http:\/\/example.com\/xmlrpc.php&quot;\r\nuser = &quot;&quot;\r\npassword = &quot;&quot;\r\n\r\nwp = Client(wordpress, user, password)\r\nposts = wp.call(GetRecentPosts(50))\r\n\r\nre_title = re.compile(u'xv6\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30ea\u30fc\u30c7\u30a3\u30f3\u30b0 \u305d\u306e(?P&lt;number&gt;\\d+)')\r\nre_description = re.compile(u'^(?P&lt;basetitle&gt;.+)\\n\u30c6\u30ad\u30b9\u30c8\u306e', re.MULTILINE | re.DOTALL)\r\n\r\nfor post in posts:\r\n    match = re_title.match(post.title)\r\n    if match:\r\n        num = match.group('number')\r\n\r\n        match = re_description.search(post.description)\r\n        if match:\r\n            basetitle = match.group('basetitle')\r\n            re_editdesc = re.compile(u'%s\\n' % re.escape(basetitle), re.MULTILINE)\r\n            new_description = re_editdesc.sub(u'', post.description)\r\n            new_title = u'&#x5B;xv6 #%s] %s' % (num, ' - '.join(basetitle.split('\\n')))\r\n            \r\n            print 'Editing %s' % new_title\r\n            \r\n            post.title = new_title\r\n            post.description = new_description\r\n            wp.call(EditPost(post.id, post, True))\r\n            \r\n            print 'Edited.'\r\n            print<\/pre>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[60,61,409],"class_list":["post-1487","post","type-post","status-publish","format-standard","hentry","category-tech","tag-python","tag-wordpress","tag-xmlrpc"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=1487"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1487\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=1487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=1487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=1487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}