Created
November 6, 2020 09:57
-
-
Save safa-dayo/75115c766f54a8eaf150f05e499bbe97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
from datetime import datetime, timedelta | |
import time | |
WP_URL = "<WordPressのURL>" | |
WP_USER = "<投稿ユーザのユーザ名>" | |
WP_PASS = "<WP REST APIで設定されたパスワード>" | |
for i in range(5): | |
time.sleep(1) | |
postdate = datetime.now() + timedelta(days=i) | |
payload = { | |
"status": "publish", | |
"slug": "testpost" + str(i+1), | |
"title": str(i+1) + "つ目の自動投稿", | |
"content": str(i+1) + "つ目の自動投稿です", | |
"date": postdate.isoformat() | |
} | |
res = requests.post(WP_URL, | |
data=json.dumps(payload), | |
headers={"Content-type": "application/json"}, | |
auth=(WP_USER, WP_PASS) | |
) | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment