python-wordpress-xmlrpc
xmlrpcでの認証等を簡単にしてくれるパッケージ
https://python-wordpress-xmlrpc.readthedocs.io/en/latest/overview.html
pip install python-wordpress-xmlrpc
# pip3 install python-wordpress-xmlrpc
記事の作成
記事を作成するサンプルコード
create_post.py
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
wp = Client('http://sample.com/xmlrpc.php', 'username', '$password')
# WordPressのURL + /xmlrpc.php, ユーザー名, パスワードを指定
post = WordPressPost()
post.title = 'title'
post.content = 'content'
post.terms_names = {
'post_tag': '',
'category': ''
}
post.post_status = 'publish'
# post.date = datetime.now() - timedelta(hours=9) + timedelta(minutes=5+(5*delay))
wp.call(NewPost(post))
python create_post.py
記事の一覧
記事の一覧を出力するサンプルコード
list_posts.py
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
wp = Client('http://sample.com/xmlrpc.php', 'username', '$password')
posts = wp.call(GetPosts({
'number': 50,
'offset': 0,
'orderby':
'modified',
'order': 'DESC',
'post_type': 'post',
'post_status': 'publish'
}))
print(posts)
python list_posts.py
# [<WordPressPost: b'title'>, <WordPressPost: b'Hello world!'>, ...]
WordPressPostのオブジェクトについては以下を参照
https://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/wordpress.html#wordpresspost