LoginSignup
3
4

More than 5 years have passed since last update.

PythonでWordPressに投稿する

Last updated at Posted at 2019-04-30

はじめに

WordPressへ定期的・自動的に記事を投稿したい。
Python + Crontab で実現できそう。
この記事は「Python」部分の忘記録です。

前準備

python-wordpress-xmlrpcのライブラリを活用する

pip install python-wordpress-xmlrpc

コード部分


wp = Client(wp_client, uid, passwd)

post = WordPressPost()
post.title = title
post.content = content

post.terms_names = {
'post_tag': tag_lst,
'category': category_lst
}

if publish:
    post.post_status = 'publish'
post.date = datetime.now() - timedelta(hours=9) + timedelta(minutes=5+(5*delay))

wp.call(NewPost(post))

パラメータの説明

  • wp_client: 「投稿先のWordPressのURL + /xmlrpc.php」
  • uid: WordPressのユーザーID
  • passwd: WordPressのパスワード
  • title: 記事タイトル
  • content: 記事の内容(htmlで記述)
  • category_lst: 記事のカテゴリー
  • tag_lst: 記事のタグ(任意)
  • post.post_status: 投稿状態(デフォルトはdraft)
  • post.date: 投稿日時(任意)。連続投稿するときはずらそう。
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4