WordPress Beitrag

Python-Skript zur automatisierten Erstellung von WordPress-Beiträgen via REST API.

🛠️ Technologie-Stack

Python 3.12 requests WordPress REST API HTTP Basic Auth Application Passwords

📋 Projektübersicht

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.

Verwendete WordPress-Features:
• Application Passwords (sichere API-Authentifizierung)
• REST API Endpoint: /wp-json/wp/v2/posts
• HTML-Content mit WordPress-konformen Tags

📝 Hauptfunktionen

🔧 Code-Beispiel

# 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
)

📂 Projektstruktur

wordpress_beitrag/
├── main.py                 # Hauptskript
├── venv/                   # Python Virtual Environment
│   ├── Lib/
│   ├── Scripts/
│   └── pyvenv.cfg
└── .idea/                  # PyCharm Konfiguration
    ├── workspace.xml
    └── ...

🔐 Sicherheit

Das Projekt verwendet WordPress Application Passwords, einen sicheren Mechanismus für API-Zugriffe ohne das Hauptpasswort preiszugeben. Die Authentifizierung erfolgt über HTTP Basic Auth.

🚀 Verwendung

  1. WordPress Application Password im Admin-Panel generieren
  2. URL, Username und Passwort im Skript konfigurieren
  3. Python-Skript ausführen: python main.py
  4. Beitrag wird als Entwurf in WordPress erstellt

Repository: Git mit PyCharm-Integration

Erstellt: Juni 2024

← Alle Projekte