This post was created automatically by running a Python script!
1. In WordPress, go to Users > click admin > at the bottom type in a New Application Password Name, click Add New Application Password, and then a password will be generated.
2. In the Python script, set this password on the password = line.
3. In the Python script, change the URL url = “https://coderfairy.com/wp-json/wp/v2”to your website. Also make sure that you change it to either https or http depending if you have a certificate installed or not.
4. Save an image named automate-wordpress-post.png to the same location as the Python script.
5. Run the Python script to automatically upload the text and image content to your WordPress post.
import requests
import json
import base64
url = 'https://coderfairy.com/wp-json/wp/v2'
user = 'admin'
password = 'oa5D 5LSk Y7xq l57E PWoS Y8is'
creds = user + ':' + password
token = base64.b64encode(creds.encode())
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
media = {
'file': open('automate-wordpress-post.png', 'rb'),
'caption': 'How to Automate a WordPress Post',
'description': 'How to Automate a WordPress Post'
}
image = requests.post(url + '/media', headers=header, files=media)
imageURL = str(json.loads(image.content)['source_url'])
post = {
'date': '2023-04-21T09:00:00',
'title': 'How to Automate a WordPress Post with Python',
'content': 'This post was created automatically by running a Python script!
' \
'1. In WordPress, go to Users > click admin > at the bottom type in a New Application Password Name, click Add New Application Password, and then a password will be generated.
' \
'2. In the Python script, set this password on the password = line.
' \
'' \
'3. In the Python script, change the URL url = "https://coderfairy.com/wp-json/wp/v2"to your website. Also make sure that you change it to either https or http depending if you have a certificate installed or not.
' \
'4. Save an image named automate-wordpress-post.png to the same location as the Python script.
' \
'5. Run the Python script to automatically upload the text and image content to your WordPress post.