WordpressのREST API v2を利用して記事の投稿・更新を行うPythonスクリプト。
Python Scripts posting/updating your article with WordPress REST API v2.
wordpress-api
is the tool that handles post/update action to your own WordPress site with CLI-based operation.
- POST article to your WordPress website with REST API over HTTPS.
- Automatically handle whether "New post" or "Update post".
- If the case "New post", this script will ask you to choose categories regarding the article.
-
WordPress with REST API v2
-
HTTPS capability (TCP:443 is opened)
Because this scripts carries authentication information in HTTP request headers(BASIC Auth code), so securing with HTTPS is strongly recommended.
-
Application Passwords plugin
-
JP Markdown plugin
-
Python3 or more
As long as python3.x is available, Windows/Mac/Linux will be fine.
-
Your articles for WordPress
IMPORTANT
This script expects that your local articles are written in Markdown
.
- To post your article:
post.py (status_option) yourfilename.md
status_option:
- -p: "published" status
- -d: "draft" status
Status option is NOT mandatory, you can handle "default status" in wp-api.ini
file.
If you don't designate status option in CLI, scripts obey "default status".
If this is the 1st time you post this article, you'll be asked which category do you correlate with.
Example:
kowloon$ post.py -p "How to use this script.md"
Please select category id.
2 : MarkDown
3 : WordPress
1 : 未分類
>>> 2,3
POST action has succeeded.
id : 119
title : How to use this script
link : https://blog.kowloonet.org/archives/119
After POST process has finished, this script adds management information
(assigned post_id, date, publishedURL) to the 1st line of your local article file which is used for next time.
- To update your articles:
kowloon$ post.py -p "How to use this script.md"
This script always reads the 1st line of your local article file and search "article_id" json code section. If "article_id" has found, this script handles your article as "Update" action.
In the case "Update", the script will not ask you category id again.
- Clone repository
$ git clone [email protected]:kowloon-dev/wordpress-api.git
- Copy .ini and log file to your home directory.
$ copy wordpress-api/files/wp-api.* ~/
- Add a path
wordpress-api.git/post.py
to your $PATH.
$ echo "export PATH=$PATH:/Users/kowloon/wordpress-api" >> ~/.bash_profile
$ source ~/.bash_profile
-
Install JP Markdown plugin on your WordPress site.
-
Install Application Passwords plugin on your WordPress site.
-
Make application password regarding your username on WordPress site.
-
Base64 Encode your name and application password.
-
Define your Base64-based Authorization code and base URL in wp-api.ini file.