{"id":222,"date":"2020-09-11T23:01:00","date_gmt":"2020-09-11T14:01:00","guid":{"rendered":""},"modified":"2022-03-15T14:00:27","modified_gmt":"2022-03-15T05:00:27","slug":"pythonwordpress","status":"publish","type":"post","link":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/2020\/09\/pythonwordpress.html","title":{"rendered":"Python\u3067WordPress\u3092\u81ea\u52d5\u6295\u7a3f\u3059\u308b\u65b9\u6cd5\uff08\u5168\u56fd\u306e\u5e02\u753a\u6751\u30da\u30fc\u30b8\u3092\u81ea\u52d5\u751f\u6210\uff09"},"content":{"rendered":"<div data-post-id=\"1297\" class=\"insert-page insert-page-1297 \"><div class=\"st-kaiwa-box kaiwaicon3 clearfix\"><div class=\"st-kaiwa-face\"><img decoding=\"async\" src=\"http:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-content\/uploads\/sites\/2\/2022\/03\/profile.jpg\" width=\"60px\"><div class=\"st-kaiwa-face-name\">\u6587\u5b57\u5b9f<\/div><\/div><div class=\"st-kaiwa-area\"><div class=\"st-kaiwa-hukidashi\">\u3053\u306e\u8a18\u4e8b\u306f\u3001\u682a\u5f0f\u4f1a\u793e\u30b7\u30b0\u30de\u30fb\u30c7\u30b6\u30a4\u30f3\u793e\u9577\u306e<a href=\"https:\/\/www.sigmadesign.co.jp\/president\/\" target=\"_blank\" rel=\"noopener\">\u6587\u5b57\u5b9f<\/a>\u304c\u57f7\u7b46\u3057\u307e\u3057\u305f\u3002<\/div><\/div><\/div>\n<\/div>\n<p>Python\u3092\u4f7f\u3063\u3066\u3001WordPress\u3092\u81ea\u52d5\u3067\u6295\u7a3f\u3059\u308b\u65b9\u6cd5\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<p>\u79c1\u304c\u3084\u308a\u305f\u304b\u3063\u305f\u3053\u3068\u306f\u3001\u5168\u5e02\u753a\u6751\u306e\u300c\u5730\u540d\uff0b\u25cb\u25cb\u300d\u3068\u3044\u3046\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u72d9\u3063\u305f\u30da\u30fc\u30b8\u3092\u81ea\u52d5\u3067\u751f\u6210\u3059\u308b\u3053\u3068\u3002<\/p>\n<p>\u5168\u5e02\u753a\u6751\u306e\u30b3\u30d4\u30fc\u30da\u30fc\u30b8\u3092\u5927\u91cf\u306b\u751f\u6210\u3059\u308b\u306e\u304c\u3001Google\u306eSEO\u7684\u306b\u52b9\u679c\u304c\u3042\u308b\u306e\u304b\u3069\u3046\u304b\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u306e\u3067\u3001\u305d\u306e\u3042\u305f\u308a\u306f\u81ea\u5df1\u8cac\u4efb\u3067\u4f7f\u3063\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<p>\u307e\u305a\u3001wordpress_xmlrpc\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u305d\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u3067\u304d\u305f\u3089\u3042\u3068\u306f\u3001\u7c21\u5358\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30da\u3057\u3066\u3001\u5b9f\u884c\u3059\u308b\u3060\u3051\u3002<\/p>\n<p>\u4f7f\u3063\u3066\u3044\u308b\u306e\u306fPython3\u3067\u3059\u3002<\/p>\n<div style=\"background-color: lightgrey; padding: 10px;\">\n<pre><code>\r\n#!\/usr\/bin\/env python\r\n#-*- coding: utf-8 -*-\r\nfrom wordpress_xmlrpc import Client, WordPressPost\r\nfrom wordpress_xmlrpc.methods.posts import GetPosts, NewPost\r\nfrom wordpress_xmlrpc.methods.users import GetUserInfo\r\nfrom datetime import datetime\r\nimport csv, codecs, time, sys, io\r\nsys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')\r\n\r\ndef main(html):\r\n    wp = Client('https:\/\/www.sample.com\/xmlrpc.php','ID','PASS') # Change \"sample.com\" to target url, and enter the user ID in \"ID\" and the password in \"PASS\".\r\n    with codecs.open(\".\/timei.csv\", \"r\", encoding=\"utf-8\") as f:\r\n        reader = csv.reader(f)\r\n        for r in reader:\r\n            timei = r[0] + r[1]\r\n            category = r[2]\r\n            image_id = r[3]\r\n            post = WordPressPost()\r\n            post.title = \"\u3010timei\u3011Enter the title name here.\".replace(\"timei\", timei) # The \"timei\" part is converted to a place name.\r\n            post.content = html.replace(\"timei\", timei)\r\n            post.terms_names = {'category': [category]}\r\n            post.thumbnail = r[3]\r\n            datetime.now()\r\n            post.post_status = 'publish'\r\n            wp.call(NewPost(post))\r\n            print(\"Post...\")\r\n            print(r)\r\n            time.sleep(2)\r\n            \r\n\r\ndef get_html():\r\n    html = \"\"\"\r\nEnter the html code you want to convert here. Put \"timei\" in the place you want to convert to a place name.\r\n\"\"\"\r\n    return html\r\n\r\nif __name__ == \"__main__\":\r\n    html = get_html()\r\n    main(html)\r\n<\/code><\/pre>\n<\/div>\n<p>\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3068\u540c\u3058\u968e\u5c64\u306b\u3001timei.csv\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u304f\u3002<\/p>\n<p>timei.csv\u30d5\u30a1\u30a4\u30eb\u306f<a href=\"https:\/\/drive.google.com\/file\/d\/1Ch9Yq4xKpF6F10Ki94dSZrMxcmeJgBUt\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\">\u3053\u3061\u3089\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/a>\u3057\u3066\u4e0b\u3055\u3044\u3002timei.csv\u306b\u306f\u5168\u56fd\u306e\u90fd\u9053\u5e9c\u770c\u3068\u5e02\u753a\u6751\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>4\u5217\u76ee\u306e\u6570\u5b57\u306f\u3001\u5404\u753b\u50cf\u306b\u5165\u308c\u305f\u3044\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1\u753b\u50cf\u306e\u753b\u50cfID\u3092\u5165\u529b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<p>\u753b\u50cfID\u306f\u3001\u5de6\u30b5\u30a4\u30c9\u30d0\u30fc\u306e\u300c\u30e1\u30c7\u30a3\u30a2\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u3001\u8abf\u3079\u305f\u3044\u753b\u50cf\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068URL\u30d0\u30fc\u306bitem=16\u3068\u3044\u3046\u3088\u3046\u306b\u6570\u5b57\u304c\u8868\u793a\u3055\u308c\u308b\u3002\u305d\u306e\u6570\u5b57\u304c\u753b\u50cfID\u3067\u3042\u308b\u3002<\/p>\n<p>\u3042\u3068\u306f\u3001\u5b9f\u884c\u3059\u308b\u3060\u3051\u3002\u5b9f\u884c\u3059\u308b\u3068\u3001timei\u3068\u8a18\u8ff0\u3057\u305f\u90e8\u5206\u304c\u3001\u5168\u56fd\u306e\u5e02\u753a\u6751\u306e\u5730\u540d\u306b\u5909\u63db\u3055\u308c\u3066\u3069\u3093\u3069\u3093\u81ea\u52d5\u6295\u7a3f\u3055\u308c\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u3057\u3070\u3089\u304f\u3001\u653e\u7f6e\u3057\u3066\u5f85\u3063\u3066\u3044\u308b\u3068\u3001\u3053\u3093\u306a\u30b5\u30a4\u30c8\u304c\u51fa\u6765\u4e0a\u304c\u308a\u3002<\/p>\n<p><a href=\"https:\/\/www.hensleycattle.com\/\" target=\"_blank\" rel=\"noopener\">\u5168\u56fd\u306e\u304a\u3059\u3059\u3081\u30c8\u30e9\u30c3\u30af\u8cb7\u53d6\u308a\u696d\u8005<\/a><\/p>\n<p>\u30a8\u30c3\u30af\u30b9\u30b5\u30fc\u30d0\u30fc\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306b\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u304c\u304b\u304b\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u4e8b\u524d\u306b\u300cWordPress\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u300d\u2192\u300cXML-RPC API \u30a2\u30af\u30bb\u30b9\u5236\u9650\u300d\u3092OFF\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u5b57\u5b9f\u3053\u306e\u8a18\u4e8b\u306f\u3001\u682a\u5f0f\u4f1a\u793e\u30b7\u30b0\u30de\u30fb\u30c7\u30b6\u30a4\u30f3\u793e\u9577\u306e\u6587\u5b57\u5b9f\u304c\u57f7\u7b46\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":223,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[33,26,34,5],"class_list":["post-222","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-python","tag-seo","tag-wordpress","tag-5"],"_links":{"self":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/posts\/222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/comments?post=222"}],"version-history":[{"count":0,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/posts\/222\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/media\/223"}],"wp:attachment":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/media?parent=222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/categories?post=222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/tags?post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}