Python-Skript zur automatisierten Erstellung von WordPress-Beiträgen via REST API.
Dieses Projekt demonstriert die Integration mit der WordPress REST API zur automatisierten Content-Erstellung. Das Skript erstellt einen formatierten WordPress-Beitrag mit HTML-Inhalt und speichert ihn als Entwurf.
# WordPress REST API Integration
import requests
from requests.auth import HTTPBasicAuth
# Authentifizierung vorbereiten
auth = HTTPBasicAuth(username, application_password)
# Beitrag-Daten
post = {
'title': 'Tutorial: Windows 10 Desktopsymbole',
'content': '<h1>...HTML-Content...</h1>',
'status': 'draft' # Als Entwurf speichern
}
# API-Anfrage
response = requests.post(
f"{wordpress_url}/wp-json/wp/v2/posts",
auth=auth,
headers={'Content-Type': 'application/json'},
json=post
)
wordpress_beitrag/
├── main.py # Hauptskript
├── venv/ # Python Virtual Environment
│ ├── Lib/
│ ├── Scripts/
│ └── pyvenv.cfg
└── .idea/ # PyCharm Konfiguration
├── workspace.xml
└── ...
Das Projekt verwendet WordPress Application Passwords, einen sicheren Mechanismus für API-Zugriffe ohne das Hauptpasswort preiszugeben. Die Authentifizierung erfolgt über HTTP Basic Auth.
python main.pyRepository: Git mit PyCharm-Integration
Erstellt: Juni 2024